This article example describes Python using matplotlib's pie function to draw a pie chart function. Shared for your reference, as follows:
For more information on how to install matplotlib, please refer to the previous article.https:///article/, the specific use of the code is as follows:
#coding=utf8 import matplotlib as mpl import numpy as np import as plt ''''' function (math.):Draw a pie chart (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:arrays。The input data is used to create a pie chart。 explode:arrays,Optional parameters,defaultNone。 if notNone,is an object of length equal tox相同长度的arrays,Used to specify the offset of each section。 for example:explode=[0,0,0.2,0,0],The second pie piece is dragged out。 labels:listings,Optional parameters,default:None。 A sequence of strings as markers for each pie slice。 colors:arrays,Optional parameters,default:None。 is used to label each pie chart'smatplotlibColor Parameter Sequence。 in case ofNone,The color of the currently active ring will be used。 autopct:The default isNone,字符串或function (math.),Optional parameters。 if notNone,be一个字符串或function (math.)用带有数值饼图标注。 pctdistance:floating point,Optional parameters,default value:0.6。 The center of each pie slice and throughautopctRatio between the beginning of the generated text。 in the event thatautopctbeNone,neglected。 shadow:boolean,Optional parameters,default value:False。 Draw a shadow below the pie chart。 labeldistance:floating point,Optional parameters,default value:1.1。 Diameter marked by the pie。 startangle:Floating point type,Optional parameters,default (setting):None。 if notNone,through (a gap)xStarting angle of the pie chart with the axis rotated counterclockwise。 radius:Floating point type,Optional parameters,default:None。 Radius of the pie chart,in the event that半径beNone,will be set to1。 counterclock:boolean,Optional parameters,default:None。 Specify pointer direction,Clockwise or counterclockwise。 wedgeprops:Dictionary Type,Optional parameters,default value:None。 A dictionary of parameters is passed to thewedge对象用来Draw a pie chart。 for example:wedgeprops={'linewidth':3}set upwedgeThe line width is3。 textprops:Dictionary Type,Optional parameters,default value为:None。 pass on totextDictionary parameters for objects。 center:Floating point type的listings,Optional parameters,default value:(0,0)。 Icon center position。 frame:Boolean type,Optional parameters,default value:False。 in the event thatbetrue,Drawing axis frames with tables。 rotatelabels:Boolean type,Optional parameters,default:False。 in case ofTrue,rotate eachlabelto the specified angle。 return value: patches:listings。an actual examplelistings。 text:listings。an actual examplelabel的listings。 autotexts:listings。Abe数字标签的Textan actual examplelistings。 Only if the parameterautopctlet sb. do sth.Nonereturn when。 ''' #Set the font style ['']='sans-serif' ['-serif']=[u'SimHei'] # Random integers from 1-11, randomly divided into five parts data=(1,11,5) # Set the offset of the second pie slice to 0.2 (data,explode=[0,0,0.2,0,0]) (u" Pie charts.") ()
Running effects:
More about Python related content can be viewed on this site's topic: theSummary of Python mathematical operations techniques》、《Python Regular Expression Usage Summary》、《Python Data Structures and Algorithms Tutorial》、《Summary of Python function usage tips》、《Summary of Python string manipulation techniquesand thePython introductory and advanced classic tutorials》
I hope that what I have said in this article will help you in Python programming.