The pie chart can be used to draw pie matplotlib library function, we first look at the function parameter description.
A: pie arguments Interpretation
plt.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)
- X : Specifies the drawing data;
- the explode : to highlight certain parts of the designated pie, that is explosively;
- Labels : add tags is illustrated as a pie chart, similar to the legend;
- Colors : Specifies pie fill color;
- autopct : automatically added percentage display, a method may be employed formatted display;
- pctdistance : set the percentage tag and the center distance;
- Shadow : whether to add the shadow effect of the pie;
- labeldistance : Set each sector tab (legend) and the center of the distance;
- startAngle : Set initial placement angle of the pie;
- RADIUS : setting the radius of the pie;
- counterclock : whether to make a pie chart showing counterclockwise order;
- wedgeprops : pie set properties inside and outside the boundary, such boundary line thickness, color and the like;
- textprops : Set pie Chinese text attributes such as font size, color and the like;
- Center : the center point of pie specified, the default is the origin Frame : whether to display the pie behind the frame, if set to True , then you need to control frame x -axis, y center position of the scope shaft and pie;
II: pie chart drawing:
1. Case I: Sesame credit dishonesty user analysis
About function parameters pie we talk so much, not just talk about practicing false skill, we are going through the case, to draw a personalized pie chart. Drawing on data, we borrow Credit Sesame sample statistics nearly three million people of dishonesty,
The data show that, from the point of view by the level of education, technical secondary school accounted for 25.15%, accounting for 37.24% junior college, undergraduate accounting for 33.36%, accounting for 3.68% master's degree , the rest of the other qualifications accounted for 0.57%. For such a set of data, how do we use it to render pie?
# Import-themed party modules disposed import matplotlib.pyplot as plt # drawing (ggplot may wish to use the separated R) plt.style.use ( 'ggplot') # configuration data edu = [0.2515,0.3724,0.3336,0.0368, 0.0057] Labels = [ ' secondary ' , ' tertiary ' , ' degree ' , ' master ' , ' other ' ] the explode = [0,0.1,0,0,0] # for highlighting colors populations college degree = [ '# 9999ff', '# ff9999 ', '# 7777aa', '# 2442aa', '# dd5555'] # # Chinese custom colors and axis negative distortion processing plt.rcParams [ 'font.sans-serif' ] = [ 'YaHei the Microsoft'] plt.rcParams [ ' axes.unicode_minus '] = False#The horizontal axis of ordinate normalization process is to ensure a perfect circle pie chart, or elliptical plt.axes (aspect = 'equal') # control range plt.xlim x-axis and y-axis (0,4) plt.ylim (0,4) # draw a pie chart plt.pie (x = edu, # drawing data of the explode = the explode, # highlight tertiary population labels labels =, # add educational level tags Colors = Colors, # set custom pie filling color autopct = ' % .1f %% ' , # set percentage format, where one decimal pctdistance = 0.8, # set the percentage of the label and the center distance labeldistance = 1.15, # provided educational level and the center of the label from startangle = 180 , # set pie initial angle rADIUS = for 1.5, # set the radius of the pie = False counterclock, # whether counterclockwise, provided herein is clockwise wedgeprops = { ' as linewidth ' : for 1.5, ' edgecolor ' : ' Green ' }, # set property values inside and outside the boundary of the pie textprops = { ' fontSize ' : 12 is , ' Color ' : ' K ' }, # attribute value text labels Center = (1.8,1.8), # set the origin pie frame =. 1) # whether the frame pie, there is provided a display delete x # scale plt.xticks axis and y-axis (()) plt.yticks (()) # Add chart title plt.title ( 'Sesame credit dishonesty user education level distribution') # display graphics plt.show ()