python pie chart with legend

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

showing results for - "python pie chart with legend"
Filippo
27 Jun 2018
1import matplotlib.pyplot as plt
2# The slices will be ordered and plotted counter-clockwise.
3labels = [r'Rayos X (88.4 %)', r'RMN en solucion (10.6 %)', 
4r'Microscopia electronica (0.7 %)', r'Otros (0.3 %)']
5sizes = [88.4, 10.6, 0.7, 0.3]
6colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']
7patches, texts = plt.pie(sizes, colors=colors, startangle=90)
8
9plt.legend(patches, labels, loc="best") # The Legend
10
11# Set aspect ratio to be equal so that pie is drawn as a circle.
12plt.axis('equal')
13plt.tight_layout()
14plt.show()