如何为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
(example).
您可以使用 axes.set_color_cycle
(example).
您可以使用Axes.set_default_color_cycle
.
这篇关于如何为matplotlib中图形中的每条绘制线选择一种新颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文