Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python pie chart with legend

import matplotlib.pyplot as plt
# The slices will be ordered and plotted counter-clockwise.
labels = [r'Rayos X (88.4 %)', r'RMN en solucion (10.6 %)', 
r'Microscopia electronica (0.7 %)', r'Otros (0.3 %)']
sizes = [88.4, 10.6, 0.7, 0.3]
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']
patches, texts = plt.pie(sizes, colors=colors, startangle=90)

plt.legend(patches, labels, loc="best") # The Legend

# Set aspect ratio to be equal so that pie is drawn as a circle.
plt.axis('equal')
plt.tight_layout()
plt.show()
Comment

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();
Comment

PREVIOUS NEXT
Code Example
Python :: required validator python WTForms 
Python :: how to get data in treeview in tkiter 
Python :: pandas convert column to index 
Python :: python hour from datetime 
Python :: how to create a car game using python 
Python :: beautiful soup 4 python 
Python :: mean deviation python 
Python :: upgrade python to 3.8 
Python :: how to get the angle of mouse from the center formulae 
Python :: matplotlib wrap title 
Python :: how to change button background color while clicked tkinter python 
Python :: insta profile downloader in python 
Python :: cv2 load image 
Python :: zipfile python 
Python :: python os output to variable 
Python :: python find the factors of a number 
Python :: get request python 
Python :: run flask application in development mode stack overflow 
Python :: get eth balance python 
Python :: date format django template filter 
Python :: how to add numbers in python using for loop 
Python :: install qt python 
Python :: python plot cut off when saving figure 
Python :: install python homebrew 
Python :: token_obtain_pair check email 
Python :: meme command discord.py 
Python :: how to remove the very last character of a text file in python 
Python :: mape python 
Python :: python magic windows error 
Python :: python random choice from list 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =