Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

legend for pie chart matplotlib

fig1, ax1 = plt.subplots()

ax1.pie(totalAmount_sample, shadow=False, startangle=90)  # No labels or %s
ax1.axis('equal')  # Equal aspect ratio ensures that pie is drawn as a circle.
fig1 = plt.gcf()
fig1.set_size_inches(5,5)
circle = plt.Circle(xy=(0,0), radius=0.75, facecolor='white')
plt.gca().add_artist(circle)

plt.legend(labels=[f'{x} {np.round(y/sum(totalAmount_sample)*100,1)}%' for x,y in crimeTypes.items()], 
           bbox_to_anchor=(1,1))

plt.show();
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #legend #pie #chart #matplotlib
ADD COMMENT
Topic
Name
7+3 =