我深入探讨了几个问题,以找到一个条件,即要在绘图中绘制多条线并从给定的颜色图中选择颜色,然后通过第三个变量值选择颜色。
类似这样的东西:
color = ['0.1', '0.8']
for i in range(2):
x = np.arange(0, 10, 0.1)
y = np.sin(x*(i+1))
pl.plot(x, y, c=color[i])
但是在这里,我只能使用gray
色表中的颜色。
另一个选择:
from cycler import cycler
NUM_COLORS = 10
cm = pl.get_cmap('gist_rainbow')
ax.set_prop_cycle(cycler('color', [cm(1.*ii/NUM_COLORS)
for ii in range(NUM_COLORS)]))
在这里可以选择一个颜色图,但是我无法控制颜色的顺序,颜色是根据绘制的线条的顺序来选择的。
我们有这样的东西吗?
# a command to choose colormap comes here
for i in range(2):
x = np.arange(0, 10, 0.1)
y = np.sin(x*(i+1))
pl.plot(x, y, c=(i or some operation on i to choose color based on index))