我想根據相應的布爾數組的值(在本例中爲annotation
)以不同的顏色顯示部分線圖。到目前爲止,我試過這個:根據Pyplot中的對應值,線的顏色不同
plt.figure(4)
plt.title("Signal with annotated data")
plt.plot(resampledTime, modulusOfZeroNormalized, 'r-',)
walkIndex = annotation == True
plt.plot(resampledTime[~walkIndex], modulusOfZeroNormalized[~walkIndex], label='none', c='b')
plt.plot(resampledTime[walkIndex], modulusOfZeroNormalized[walkIndex], label='some', c='g')
plt.show()
但是,這一個加入兩種顏色,背景顏色也是可見的。
我碰到了BoundaryNorm
,但我認爲它需要y值。
任何想法如何在一些地區不同顏色的線?
你可以使用'np.ma.masked'而不是'np.nan',然後'matplotlib'排除它 – Bart