我正在使用一个函数在一个图中绘制4个饼图。但是,我意识到,取决于字典中键名的持续时间,饼图会移动。如何解决这个问题并使它们保持如图1所示?
这是我的职能:
def create_pie_chart(title, pie_dict, top_design, pyplot, nbr, cord1, cord2, loc_nbr):
#pyplot.figure()
counts = collections.Counter(pie_dict) # color for pie chart
pyplot.subplot(2, 2, nbr)
pyplot.pie([float(v) for v in counts.values()], labels=[k for k in counts],
autopct='%1.1f%%', radius=9, shadow=True, labeldistance=1.05, startangle=125,
pctdistance=0.7, center=(cord1, cord2))
centre_circle = pyplot.Circle((0,0), 2, fc='white')
pyplot.gca().set_title(title+top_design)
fig = pyplot.gcf()
fig.gca().add_artist(centre_circle)
#pyplot.suptitle(title+top_design)
pyplot.axis('equal')
pyplot.legend(labels=counts, loc='center right', fontsize = 'x-small', bbox_to_anchor=(0.2, 0.2, 1, 1), facecolor='grey')
pyplot.tight_layout()
pyplot.title(title+top_design, fontsize = 'medium')
我这样称呼:
create_pie_chart("second pie chart\n ", dict_2, "two", pyplot, 2, 0, 0, 1)