Data Visualization Python - Pie

matplotlib module

Matplotlib selection module draw a pie chart, the first sub-module pyplot need to import the module, and then calls the function module pie

pie(x, explode, labels, colors, autopct, pctdistance, shadow, labeldistance, startangle, radius, counterclock, wedgeprops, textprops, center=(0,0), frame=False)

x: the drawing data, when the assignment x may be with or without such, x = edu, or direct write edu

startangle: initial placement angle of the pie
counterclock: whether to make a pie chart showing counterclockwise order, are: True counterclockwise, No: False Clockwise
Note: No matter counterclockwise or clockwise to the right level to 0 degrees, if startangle = 60, 60 degrees counterclockwise, of the start position of the pie

explode: Specifies certain parts highlighted pie, i.e., the form of split shaped, explosive, and other portions of the separate
labels: label instructions pie, i.e., the content of each block represented by the
colors: color pie filling, color representation you can use hexadecimal, you can also use the name of a specific color, such as red

explode, labels, color: the need to position data x, the position data set corresponding to these three properties, three properties set in advance, and then call the function
explode = [0,0.1,0,0,0] : 0.1 is simply more piece of the pie to split from the center point

autopct: Adding percentage shows the proportion of each piece of the pie chart is displayed as a percentage of
a percentage formatting:.% 1f %%, use 2% in order to show the percent sign

pctdistance: set the percentage of the label and the center distance
labeldistance: tag label attribute display and the center distance

radius: radius of the pie chart radius: radius, radius
wedgeprops: the inner and outer border attribute pie, e.g., the thickness of the boundary line linewidth, color, etc. edgecolor
the wedgeprops attributes are the individual pie tile boundary
wedgeprops provided value, a dictionary format, wedgeprops = { 'linewidth': 15, 'edgecolor': 'green'}

textprops: Set pie Chinese text attributes such as font size fontSize, color color
value tag, label text, graphics title title

import matplotlib.pyplot as plt
import pandas as pd


plt.rcParams['font.sans-serif']=['Microsoft YaHei']
plt.rcParams['axes.unicode_minus']=False

edu=(0.2515,0.3724,0.33336,0.0368,0.0057)
labels=('中专','大专','本科','硕士','其他')
explode=[0,0.1,0,0,0]
color=['yellow','red','brown','green','purple']
plt.axes(aspect='equal')


plt.pie(x=edu,labels=labels,autopct='%.1f%%',
explode=explode,colors=color,
wedgeprops={'linewidth':1.5,'edgecolor':'black'},
textprops={'fontsize':10,'color':'black'})

plt.title('失信用户的受教育水平分布')
plt.show()

14227815-55302a28561eea6d.png
image.png

Guess you like

Origin blog.csdn.net/weixin_33895604/article/details/90802106