Python uses the pie function of matplotlib to draw a pie chart. matplotlibpie

Source: Internet
Author: User
Tags install matplotlib

Python uses the pie function of matplotlib to draw a pie chart. matplotlibpie

This article describes how to use matplotlib's pie function to draw a pie chart in Python. We will share this with you for your reference. The details are as follows:

For details about how to install matplotlib, refer to the previous article http://www.bkjia.com/article/51812.htm. the specific use code is as follows:

# Coding = utf8import matplotlib as mplimport numpy as npimport matplotlib. pyplot as plt ''' matplotlib. pyplot. pie function: Draw a pie chart matplotlib. pyplot. pie (x, explode = None, labels = None, colors = None, autopct = None, pctdistance = 0.6, shadow = False, labeldistance = 1.1, startangle = None, radius = None, counterclock = True, wedgeprops = None, textprops = None, center = (0, 0), frame = False, rotatelabels = False, hold = None, data = None) parameter description: X: array. The input data is used to create a pie chart. Explode: array, which is an optional parameter. The default value is None. If it is not None, an array of the same length as x is used to specify the offset of each part. For example: explode = [0.2,], the second pie block is dragged out. Labels: List. An optional parameter. The default value is None. A string sequence is used as a marker for each pie block. Colors: array. An optional parameter. The default value is None. The matplotlib color parameter sequence used to mark each pie chart. If it is None, the color of the current active ring is used. Autopct: The default value is None. It is a string or function. Optional. If it is not None, it is a string or function marked with a pie chart with values. Pctdistance: floating point number. An optional parameter. Default Value: 0.6. The ratio between the center of each pie slice and the beginning of the text generated by autopct. If autopct is None, it is ignored. Shadow: Boolean value. An optional parameter. Default Value: False. Draw a shadow under the pie chart. Labeldistance: floating point number. An optional parameter. Default Value: 1.1. The diameter marked by the pie. Startangle: floating point type. Optional. Default Value: None. If it is not None, rotate the starting angle of the pie chart counterclockwise from the X axis. Radius: floating point type. Optional. Default Value: None. Radius of the pie chart. If the radius is None, it is set to 1. Counterclock: Boolean value. An optional parameter. The default value is None. Specifies the pointer direction, clockwise or counterclockwise. Wedgeprops: dictionary type. Optional. Default Value: None. The parameter dictionary is passed to the wedge object to draw a pie chart. For example, wedgeprops = {'linewidth': 3} sets the wedge width to 3. Textprops: The dictionary type. It is an optional parameter. The default value is None. The dictionary parameter passed to the text object. Center: a list of floating point types. An optional parameter. Default Value: (0, 0 ). The center of the icon. Frame: boolean type. Optional. Default Value: False. If it is true, draw an axis frame with a table. Rotatelabels: boolean type. Optional. Default Value: False. If it is True, rotate each label to the specified angle. Returned value: patches: list. Matplotlib. patches. Wedge instance list. Text: list. Matplotlib. text. Text instance label list. Autotexts: list. A is the Text instance list of numeric tags. It is returned only when the autopct parameter is not set to None. ''' # Set the font style mpl. rcParams ['font. family '] = 'sans-serif 'mpl. rcParams ['font. sans-serif'] = [u'simhei'] # random integers from 1 to 11 are randomly divided into five data = np. random. randint (0.2, 5) # Set the offset of the second pie block to 0.2plt.pie (data, explode = [,]) plt. title (u "www.jb51.net pie chart") plt. show ()

Running effect:

Related Article

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.