如何在matplotlib中为图形中的每个绘图线选择新颜色?
问题描述:
我不想为每条绘制的线指定颜色,而是让每条线获得不同的颜色.但是,如果我运行:
I'd like to NOT specify a color for each plotted line, and have each line get a distinct color. But if I run:
from matplotlib import pyplot as plt
for i in range(20):
plt.plot([0, 1], [i, i])
plt.show()
然后我得到以下输出:
如果您查看上面的图片,您会看到matplotlib尝试为每行选择不同的颜色,但最终它重新使用了颜色-前十行与后十行使用相同的颜色.我只是想阻止它重复使用已经使用过的颜色和/或为它提供要使用的颜色列表.
If you look at the image above, you can see that matplotlib attempts to pick colors for each line that are different, but eventually it re-uses colors - the top ten lines use the same colors as the bottom ten. I just want to stop it from repeating already used colors AND/OR feed it a list of colors to use.