2014-01-10 34 views
5

我有超過40個項目要顯示在我的圖表中。 我只有10種顏色重複顯示在圖表上。我怎樣才能生成更多的顏色。如何在餅圖上生成更多顏色matplotlib

plt.pie(f,labels=labels,autopct='%1.1f%%', startangle=90,shadow=True) 

我應該添加「顏色=顏色」的顏色無限生成?

回答

20

您需要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() 

enter image description here

除了使用色彩映射表,也可以考慮使用.set_color_cycle()方法。看到這篇文章:plotting different colors in matplotlib