legend for pie chart matplotlib

Solutions on MaxInterview for legend for pie chart matplotlib by the best coders in the world

showing results for - "legend for pie chart matplotlib"
Marie
11 Jun 2018
1fig1, ax1 = plt.subplots()
2
3ax1.pie(totalAmount_sample, shadow=False, startangle=90)  # No labels or %s
4ax1.axis('equal')  # Equal aspect ratio ensures that pie is drawn as a circle.
5fig1 = plt.gcf()
6fig1.set_size_inches(5,5)
7circle = plt.Circle(xy=(0,0), radius=0.75, facecolor='white')
8plt.gca().add_artist(circle)
9
10plt.legend(labels=[f'{x} {np.round(y/sum(totalAmount_sample)*100,1)}%' for x,y in crimeTypes.items()], 
11           bbox_to_anchor=(1,1))
12
13plt.show();
14