2017-03-06 67 views
0

我试图创建一个饼图,如下:更好的饼图配色方案

import matplotlib.pyplot as plt 
import pandas as pd 

# make a square figure and axes 
plt.figure(1, figsize=(10,10)) 
plt.axes([0.01, 0.1, 0.6, 0.6]) 
# plt.style.use('fivethirtyeight') 

# The slices will be ordered and plotted counter-clockwise. 
labels = 'foo1', 'foo2', 'foo3', 'foo4' 
fracs = pd.Series([10,30, 50,10],index=labels) 
fracs.plot(kind='pie', labels=None, autopct='%1.0f%%') 
plt.legend(bbox_to_anchor=(0.95, .9), loc=2, borderaxespad=0.,labels=labels) 
plt.title('pie chart demo which should be center aligned not left', bbox={'facecolor':'0.8', 'pad':5}) 

plt.show() 

这是yeilding一个饼图为:enter image description here 不过,我面临两个问题: 1)我不喜欢的配色方案。我希望颜色方案更符合enter image description here(我需要12种颜色) 2)标题仅以饼图为中心。这个传说不知何故。我试图让标题集中在图表和图例上。

有人可以帮忙吗?

回答

0

我认为这是一个ggplot colorscheme,你试图效仿。

而你的plt.axes命令是将图表移动到左侧。

试试这个:

import matplotlib.pyplot as plt 

plt.style.use('ggplot') 
plt.figure(1, figsize=(10,10)) 

labels = 'foo1', 'foo2', 'foo3', 'foo4' 
sizes = [10,30, 50,10] 
plt.pie(sizes, labels=labels) 
plt.show() 

enter image description here