I would like to plot a pie chart that shows contributions that are more than 1%, and their corresponding legend label.
I have managed showing the percentage values I wanted on the pie (see script below), but not the legend labels. In the following example, I want to show legend labels ABCD, but not EF.
I have tried several things, but only able to show either a full legend, or a filtered legend with unmatched (wrong) colors.
How can I do this? Can someone help? Thanks.
sizes = pd.DataFrame([80,10,5,4,0.1,0.9],index=list("ABCDEF"))
fig1, ax2 = plt.subplots()
def autopct_more_than_1(pct):
return ('%1.f%%' % pct) if pct > 1 else ''
ax2.pie(sizes.values, autopct=autopct_more_than_1)
ax2.axis('equal')
plt.legend(sizes.index, loc="best", bbox_to_anchor=(1,1))
plt.show()