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我只是通过你现在建议的问题。 –