我试图改变从两个数组中的数据绘制的线的颜色(例如ax.plot(x,y)
).颜色应作为索引变化x
和y
增加.我基本上是试图捕捉自然的"时间"的数据在阵列参数x
和y
.
在一个完美的世界里,我想要一样的东西:
fig = pyplot.figure()
ax = fig.add_subplot(111)
x = myXdata
y = myYdata
# length of x and y is 100
ax.plot(x,y,color=[i/100,0,0]) # where i is the index into x (and y)
Run Code Online (Sandbox Code Playgroud)
生产一条颜色从黑色到深红色变为亮红色的线.
我想绘制(x,y)平面中的曲线,其中曲线的颜色取决于另一个变量T的值.x是1D numpy数组,y是1D numpy数组.
T=np.linspace(0,1,np.size(x))**2
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x,y)
Run Code Online (Sandbox Code Playgroud)
我希望线条从蓝色变为红色(使用RdBu色彩映射),具体取决于T的值(每个(x,y)对存在一个T值).
我找到了这个,但我不知道如何将它改为我的简单例子.我如何使用linecollection作为我的例子?http://matplotlib.org/examples/pylab_examples/multicolored_line.html
谢谢.
matplotlib ×2