0
我無法繪製一個變量,其中的點通過引用而被着色。我最終想要的是每個點的線段(連接到下一個點)是一種特定的顏色。我嘗試了Matplotlib
和pandas
。每種方法都會引發不同的錯誤。嘗試在Python中繪製多色線時發生錯誤
生成趨勢線:
datums = np.linspace(0,10,5)
sinned = np.sin(datums)
plt.plot(sinned)
所以現在我們產生了一個新的標籤欄:
sinned['labels'] = np.where((sinned < 0), 1, 2)
print(sinned)
能產生我們的最終數據集:
0 labels
0 0.000000 2
1 0.598472 2
2 -0.958924 1
3 0.938000 2
4 -0.544021 1
現在的陰謀企圖:
plt.plot(sinned[0], c = sinned['labels'])
這會導致錯誤:length of rgba sequence should be either 3 or 4
我也嘗試設置標籤是字符串'r'
或'b'
,這並沒有工作,要麼:-/
的可能的複製[蟒:如何繪製不同的顏色一行](http://stackoverflow.com/questions/17240694/python-how-to-plot-one-line在不同的顏色) – ImportanceOfBeingErnest
看看這個問題:http://stackoverflow.com/questions/17240694/python-how-to-plot-one-line-in-different-colors此外,還有一個matplotlib [示例關於着色行](http://matplotlib.org/examples/pylab_examples/multicolored_line.html) – ImportanceOfBeingErnest
@ImportanceOfBeingErnest我只是通過你現在建議的問題。 –