如何在matplotlib中为图形中的每个绘图线选择新颜色? [英] How to pick a new color for each plotted line within a figure in matplotlib?
本文介绍了如何在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.
推荐答案
matplotlib 1.5 +
您可以使用axes.set_prop_cycle
(示例).
您可以使用axes.set_color_cycle
(示例).
您可以使用Axes.set_default_color_cycle
.
这篇关于如何在matplotlib中为图形中的每个绘图线选择新颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文