Python uses the matplotlib library to draw a pie chart.

Source: Internet
Author: User
Tags install matplotlib

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.