Python 3.x 更好的颜色方案
我正在尝试创建一个饼图,如下所示:Python 3.x 更好的颜色方案,python-3.x,pandas,matplotlib,pie-chart,Python 3.x,Pandas,Matplotlib,Pie Chart,我正在尝试创建一个饼图,如下所示: 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
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()
这是一个饼图,如下所示:
但是,我面临两个问题:
1) 我不喜欢这个配色方案。我想要一个更内联的配色方案(我需要12种颜色)
2) Titel仅在饼图中居中。这个传说不知怎的被打破了。我试图让标题集中在图表和图例上
有人能帮忙吗?我想这是一个你正在尝试模仿的ggplot配色方案 而您的
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()