pie函数--Matplotlib

matplotlib.pyplot.pie

函数功能: Plot a pie chart.
                  绘制饼图
Make a pie chart of array x. The fractional area of each wedge is given by x/sum(x). If sum(x) < 1, then the values of x give the fractional area directly and the array will not be normalized. The resulting pie will have an empty wedge of size 1 - sum(x).
The wedges are plotted counterclockwise, by default starting from the x-axis.
绘制数组x的饼图,每个楔形的局部面积通过 x / s u m ( x ) x/sum(x) x/sum(x)计算得到。如果 s u m ( x ) sum(x) sum(x)小于1,x的值直接反应每部分楔形的面积,这时数组不会被标准化。产生的饼图会有大小为 1 − s u m ( x ) 1-sum(x) 1sum(x)的空楔形部分。
默认情况下楔形是从从x轴开始逆时针绘制的。

函数语法: pie(x, explode=None, labels=None, colors=None, autopct=None, pctdistance=0.6, shadow=False, labeldistance=1.1, startangle=0, radius=1, counterclock=True, wedgeprops=None, textprops=None, center=0, 0, frame=False, rotatelabels=False, *, normalize=None, data=None)

函数参数:
x: 1D array-like。The wedge sizes
x: 一维数据。决定楔形面积大小
在这里插入图片描述

explode: array-like, default: None。If not None, is a len(x) array which specifies the fraction of the radius with which to offset each wedge.

裂开:数组,默认值为空,默认情况下,各部分均不远离圆心。若非空,则为与x长度相同的数组,参数 e x p l o d e explode explode指定每个楔形距离圆心的距离是半径的多少比例

当参数 e x p l o d e = 0.5 explode=0.5 explode=0.5,即每块区域都离圆心0.5倍的半径距离
在这里插入图片描述
当参数 e x p l o d e = 0.5 explode=0.5 explode=0.5,即每块区域都离圆心0.1倍的半径距离
在这里插入图片描述
当参数 e x p l o d e explode explode,取值各不同,则即每块区域离圆心不同的距离
在这里插入图片描述
labels: list, default: None。A sequence of strings providing the labels for each wedge
标签:列表,默认值为None。是一系列字符串,提供每块楔形的标签
在这里插入图片描述
colors: array-like, default: None。A sequence of colors through which the pie chart will cycle. If None, will use the colors in the currently active cycle.
颜色:数组,默认为None。饼图将循环显示的一系列颜色。若为空,将使用当前活动周期中的颜色。
实践表明,颜色的个数不需要与x的长度一致,颜色会循环展示。
一种颜色展示
在这里插入图片描述
两种颜色展示
在这里插入图片描述

三种颜色展示
在这里插入图片描述
四种颜色展示

在这里插入图片描述
autopct: None or str or callable, default: None
If not None, is a string or function used to label the wedges with their numeric value. The label will be placed inside the wedge. If it is a format string, the label will be fmt % pct. If it is a function, it will be called.
数据百分比标注格式:取值为None,字符串,可调用对象,默认值为None。若非空,是用于标记楔形数值的字符串或者函数。标签会放在楔形内部。如果标签为格式字符串,其格式为 f m t fmt% fmt,若是一个函数,将会被调用。

在这里插入图片描述
补充:

%f格式
**%f:**不指定宽度,整数部分全部输出,并输出6个小数位。
%m.nf:最小输出宽度为m个字符,数值精度为n。若数字宽度小于m,则在整数前面补空格;若数字宽度大于m,则全部输出
在这里插入图片描述

f = 5.6
g=23566.652
# 默认情况,整数部分全部输出,小数部分6位
print('%f'%f)
# 指定最小输出m与数字精度n
print('%3.2f'%f)
print('%5.2f'%f)
print('%7.2f'%f)
# 数据位数超出m,完整输出
print('%5.2f'%g)

在这里插入图片描述
明显可以看出当最小宽度m变大时,数字在饼图中因为在前面补空格而向后退。
在这里插入图片描述
pctdistance: float, default: 0.6。 The ratio between the center of each pie slice and the start of the text generated by autopct. Ignored if autopct is None.
浮点型,默认0.6。反应每块扇形的中心(每个扇形的圆心位置)与参数 a u t o p c t autopct autopct产生的数值之间的距离与半径的比例。若未设置参数 a u t o p c t autopct autopct则该参数也不生效。
当参数 p c t d i s t a n c e = 0 pctdistance=0 pctdistance=0,参数 a u t o p c t autopct autopct产生的数值在每块扇形的圆心位置
在这里插入图片描述
当参数 p c t d i s t a n c e = 0.6 pctdistance=0.6 pctdistance=0.6,参数 a u t o p c t autopct autopct产生的数值距离每块扇形圆心0.6倍距离的地方
在这里插入图片描述
当参数 p c t d i s t a n c e = 1 pctdistance=1 pctdistance=1,参数 a u t o p c t autopct autopct产生的数值恰好在每块扇形的边缘位置
在这里插入图片描述

shadow: bool, default: False。Draw a shadow beneath the pie
阴影:布尔型,默认值False:无阴影。绘制饼图的阴影
当参数 s h a d o w = T r u e shadow=True shadow=True,结果展示如下:
在这里插入图片描述
在这里插入图片描述

  • 尚不理解
  • normalize: None or bool, default: None When True, always make a full pie by normalizing x so that sum(x) == 1. False makes a partial pie if sum(x) <= 1 and raises a ValueError for sum(x) >1.When None, defaults to True if sum(x) >= 1 and False if sum(x) <1.Please note that the previous default value of None is now deprecated, and the default will change to True in the next release. Please pass normalize=False explicitly if you want to draw a partial pie.
    labeldistance: float or None, default: 1.1。 at which the pie labels are drawn. If set to None, label are not drawn, but are stored for use in legend()
    标签距离:浮点型或者None,默认浮点型1.1。饼图标签的径向距离。若设置为None,标签不会被展示,但是可以展示在legend中

参数 l a b e l d i s t a n c e = 1 labeldistance=1 labeldistance=1
在这里插入图片描述
参数 l a b e l d i s t a n c e = 1.2 labeldistance=1.2 labeldistance=1.2
在这里插入图片描述

参数 l a b e l d i s t a n c e = N o n e labeldistance=None labeldistance=None,标签不展示
在这里插入图片描述

参数 l a b e l d i s t a n c e = N o n e labeldistance=None labeldistance=None,标签在图例中展示在这里插入图片描述
若参数 l a b e l d i s t a n c e labeldistance labeldistance使用默认值1.1,同时有legend,则展示一次标签,一次图例。
在这里插入图片描述
startangle: float, default: 0 degrees。 The angle by which the start of the pie is rotated, counterclockwise from the x-axis.
起始角:浮点型,默认值是0°,起始饼旋转的角度,从x轴逆时针旋转。
在这里插入图片描述
radius: float, default: 1。The radius of the pie.
半径:浮点型,默认长度为1。饼的半径

参数 r a d i u s = 1.5 radius=1.5 radius=1.5,此图明显变大。
在这里插入图片描述
counterclock: bool, default: True。Specify fractions direction, clockwise or counterclockwise.
是否逆时针绘图:布尔型,默认值为True逆时针。指定绘制图形的顺时针与逆时针
参数 c o n u t e r c l o c k = F a l s e conuterclock=False conuterclock=False,顺时针绘图。
在这里插入图片描述
wedgeprops: dict, default: None
Dict of arguments passed to the wedge objects making the pie. For example, you can pass in wedgeprops = {‘linewidth’: 3} to set the width of the wedge border lines equal to 3. For more details, look at the doc/arguments of the wedge object. By default clip_on=False.
楔形边界属性设置:字典类型,默认值None.字典参数传递给楔形对象来绘制饼图。例如:传递 ′ l i n e w i d t h ′ : 3 {'linewidth': 3} linewidth:3 来设置楔形边界线的宽度等于3。更多详细内容查看楔形对象的文档/参数。

在这里插入图片描述
textprops: dict, default: None
Dict of arguments to pass to the text objects.

文本属性:字典属性,默认值:None
传递给文本对象的参数字典

在这里插入图片描述
center: (float, float), default: (0, 0)
The coordinates of the center of the chart.
中心:一对浮点型坐标,默认位置:(0,0)
图标中的坐标

设置参数 c e n t e r = ( 6 , 6 ) center=(6,6) center=(6,6)饼状图圆心在(-6,-6)位置,因为鼠标点的时候没有精确定位,所以显示的数值有一点偏差
在这里插入图片描述
参数 c e n t e r center center为空,默认在(0,0)位置
在这里插入图片描述
frame: bool, default: False
Plot axes frame with the chart if true.
框架:布尔型,默认False:无框架
若为真,绘制图标的坐标系框架。
设置参数 f r a m e = T r u e frame=True frame=True,绘制出来一个框架!这个框架的范围从(0,0)到(1,1)

在这里插入图片描述

rotatelabels: bool, default: False
Rotate each label to the angle of the corresponding slice if true.
旋转标签文本:布尔型,默认值False:不旋转
若为真,将标签旋转到相应角度

参数 r o t a t e l a b e l s = 30 rotatelabels=30 rotatelabels=30
在这里插入图片描述

官方文档:链接 https://matplotlib.org/api/_as_gen/matplotlib.pyplot.pie.html

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值