我在我的图表中显示了超过40个项目.我只有10种颜色反复显示在图表上.如何生成更多颜色.
plt.pie(f,labels=labels,autopct='%1.1f%%', startangle=90,shadow=True)
我应该添加"color = colors",其中颜色是无限生成的?
你需要colors
参数,旁边你可以使用一些颜色图cm
.
>>> import matplotlib.pyplot as plt >>> from matplotlib import cm >>> import numpy as np >>> a=np.random.random(40) >>> cs=cm.Set1(np.arange(40)/40.) >>> f=plt.figure() >>> ax=f.add_subplot(111, aspect='equal') >>> p=plt.pie(a, colors=cs) >>> plt.show()
除了使用colormaps之外,还要考虑使用.set_color_cycle()
方法.看这篇文章:在matplotlib中绘制不同的颜色