擅长:python、mysql、java
<p>您可以计算每行的颜色,例如计算红、绿、蓝值,每行的间隔为[0,1]:</p>
<pre><code>import matplotlib.pyplot as plt
plt.figure()
for i in range(0,19):
plt.plot((-0.1, 0.6),(i, i), color=((20-i)/20., 0, i/20.))
plt.ylim([0,20])
plt.xlim([-0.1,0.6])
plt.xlabel('Posicion [m]')
plt.ylabel('Velocidad [m/s]')
plt.show()
</code></pre>
<p><a href="https://i.stack.imgur.com/tbvsf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tbvsf.png" alt="enter image description here"/></a></p>
<p>另外,还可以考虑指定一个colorbar并选择color值作为colorbar中的一个位置,这样可以让您快速适应不同期刊的标准,或者色盲类型的表示等。为此,请查看matplotlib <a href="http://matplotlib.org/examples/pylab_examples/line_collection2.html" rel="nofollow noreferrer">LineCollection examples</a>:从长远来看,集合很适合使用,你已经为他们整理好你的数据了?7colormap是LineCollection的属性,它向示例中添加一行:</p>
^{pr2}$
<p>结果:</p>
<p><a href="https://i.stack.imgur.com/I5u70.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/I5u70.png" alt="enter image description here"/></a></p>