将数据拆分为单独的系列并分别绘制这些系列:
import matplotlib.pyplot as plt
X = [1,2,3,4,5,6,7,8]
Y = [0,50,100,0,25,50,75,100]
split = list()
for i,y in enumerate(Y):
if (y == 100): split += [i,]
prev = 0
for nxt in split:
plt.plot(X[prev:nxt+1],Y[prev:nxt+1],c='b')
prev = nxt+1
plt.show()