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 :: transformers bert 
Python :: scrapy shell 
Python :: how to access the last element of a list in python 
Python :: shallow copy in python 
Python :: python get numbers after decimal point 
Python :: fahrenheit to celsius in python 
Python :: train dev test split sklearn 
Python :: add option in python script 
Python :: python program to print inverted star pattern 
Python :: python lambda function if else 
Python :: python import file from different directory 
Python :: how to make a random int in python 
Python :: get current url with parameters url django 
Python :: how to set numerecal index in pandas 
Python :: change data type python 
Python :: convert list to string separated by comma python 
Python :: pip install pandas Getting requirements to build wheel 
Python :: pythagorean theorem python 
Python :: how to take a column from dataset in python 
Python :: how to fix def multiply(a ,b): a*b 
Python :: how to get mac address in python 
Python :: flatmap in python 
Python :: how to add createsuper user in django 
Python :: nested loop 
Python :: get method in python dictionary 
Python :: matplotlib legend get handles 
Python :: how to change the colour of axes in matplotlin 
Python :: pandas count number of repetitions of each diferent value 
Python :: character to ascii python 
Python :: datetime column only extract date pandas 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =