Python 熊猫的重叠图例用饼图绘制

Python 熊猫的重叠图例用饼图绘制,python,pandas,matplotlib,Python,Pandas,Matplotlib,我正在使用pandas plot函数绘制饼图,并使用以下代码和matplotlib: plt.figure(figsize=(16,8)) # plot chart ax1 = plt.subplot(121, aspect='equal') dfhelp.plot(kind='pie', y = 'Prozentuale Gesamt', ax=ax1, autopct='%1.1f%%', startangle=90, shadow=False, labels=dfh

我正在使用pandas plot函数绘制饼图,并使用以下代码和matplotlib:

plt.figure(figsize=(16,8))
# plot chart
ax1 = plt.subplot(121, aspect='equal')
dfhelp.plot(kind='pie', y = 'Prozentuale Gesamt', ax=ax1, autopct='%1.1f%%',
            startangle=90, shadow=False, labels=dfhelp['Anzahl Geschäfte in der Gruppe'], legend = False, fontsize=14)
plt.show
输出如下所示:


问题是,百分比和图例是重叠的,你有办法解决吗?对于绘图,我使用了这个。

在我看来,这是一个更容易阅读的版本(但要归功于这个答案使之成为可能)

导入matplotlib.pyplot作为plt
作为pd进口熊猫
d={'col1':['Tesla','GM','Ford','Nissan','Other'],
'col2':[117,95,54,10,7]}
df=pd.DataFrame(数据=d)
打印(df)
#计算百分比和分数
百分比=100.*df.col2/df.col2.sum()
#以“制造商-百分比%”格式书写标签
labels=['{0}-{1:1.2f}%'.zip中i,j的格式(i,j)(df.col1,percent)]
ax=df.col2.plot(kind='pie',labels=None)#饼图
轴(“相等”)#相等的纵横比确保饼图绘制为圆形
ax.yaxis.label.set#u visible(False)#禁用y轴标签
#添加图例
ax.图例(标签,loc='best',bbox_至_锚=(-0.1,1.),fontsize=8)
plt.show()

从文档中可以看出,这是因为你有很多小楔子。你也许可以跟随它来解决这个问题。