Python uses the matplotlib library to draw a pie chart.
Introduction
Matplotlib is the most famous Drawing Library in python. It provides a complete set of command APIs similar to matlab and is very suitable for interactive plotting. It can also be easily used as a drawing control and embedded into GUI applications.
Its documentation is quite complete, and there are hundreds of thumbnails on the Gallery page. After opening it, all the source programs are available. Therefore, if you want to draw a certain type of graph, you can simply browse, copy, and paste the graph on this page.
You can click here to install matplotlib.
This article describes how to use matplotlib to draw a pie chart in python.
Sample Code
import matplotlib.pyplot as plt# The slices will be ordered and plotted counter-clockwise.labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'sizes = [15, 30, 45, 10]colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']explode = (0, 0.1, 0, 0) # only "explode" the 2nd slice (i.e. 'Hogs')plt.pie(sizes, explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', shadow=True, startangle=90)# Set aspect ratio to be equal so that pie is drawn as a circle.plt.axis('equal')plt.savefig('D:\\pie.png')plt.show()
Result
Summary
The above is all about this article. I hope this article will help you in your study or work. If you have any questions, please leave a message.