栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python 学习笔记之 matplotlib(饼图)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python 学习笔记之 matplotlib(饼图)

matplotlib的一些参数

The following format string characters are accepted to control the line style or marker:

characterdescription
‘-’solid line style
‘–’dashed line style
‘-.’dash-dot line style
‘:’dotted line style
‘.’point marker
‘,’pixel marker
‘o’circle marker
‘v’triangle_down marker
‘^’triangle_up marker
‘<’triangle_left marker
‘>’triangle_right marker
‘1’tri_down marker
‘2’tri_up marker
‘3’tri_left marker
‘4’tri_right marker
‘s’square marker
‘p’petagon marker
‘*’star marker
‘h’hexagon1 marker
‘H’hexagon2 marker
‘+’plus marker
‘x’x marker
‘D’diamond marker
‘d’thin_diamond marker
‘_’hline marker

The following color abbreviations are supported:

characterdescription
‘b’blue
‘g’green
‘r’red
‘c’cyan(青色)
‘m’magenta(紫红色)
‘y’yellow
‘k’black
‘w’white

In addition, you can specify colors in many weird and wonderful ways, including full names(‘green’), hex string (’#008000’), RGB or RGBA tuples((0,1,0,1)) or grayscale intensities as a string (‘0.8’).

Line styles and colors are combined in a single format string, as in ‘bo’ for blue circles.

matplotlib 实例说明之饼图——pie

一个例子:

import matplotlib.pyplot as plt
labels = 'frogs', 'hogs', 'dogs', 'logs'
sizes = 15, 20, 45, 10
colors = 'yellowgreen', 'gold', 'lightskyblue', 'lightcoral'
explode = 0, 0.1, 0, 0
plt.pie(sizes, explode = explode, labels = labels, colors = colors, autopct = '%1.2f%%', shadow = True, startangle = 50)
# autopct = %1.2f%% ; 小数点后面的数字表示保留小数点几位 ; 分别设置为 %1.2f% 和%1.1f%% 结果分别如1、2图所示
plt.axis('equal')
plt.show()

图片1

图片2

pie 的参数说明:

参数说明
x(每一块)的比例,如果sum(x) > 1会使用sum(x)归一化
labels(每一块)饼图外侧显示的说明文字
explode(每一块)离开中心距离
startangle起始绘制角度;默认图是从x轴正方向逆时针画起;如设定=90则从y轴正方向画起
shadow在饼图下面画一个阴影;默认值:False,即不画阴影
labeldistancelabel标记的绘制位置,相对于半径的比例;默认值为1.1,如<1则绘制在饼图内侧
autopct控制饼图内百分比设置,可以使用format字符串或者format function; ‘%1.1f’ 指小数点前后位数(没有用空格补齐)
pctdistance类似于labeldistance,指定autopct的位置刻度,默认值为0.6
radius控制饼图半径,默认值为1
counterclock指定指针方向;布尔值,可选参数,**默认为:True,即逆时针;**将值改为False即可改为顺时针
wedgeprops字典类型,可选参数,默认值:None;参数字典传递给 wedge 对象用来画一个饼图。例如:wedgeprops = { ‘linewidth’ : 3 } 设置wedge线宽为3
textprops设置标签(labels)和比例文字的格式;字典类型,可选参数,默认值为:None;传递给text对象的字典参数
center浮点类型的列表,可选参数,默认值:(0,0),图标中心位置
frame布尔类型,可选参数,默认值:False;如果是true,绘制带有表的轴框架
rotatelabels布尔类型,可选参数,默认为:False;如果为True,旋转每个label到指定的角度
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/293663.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号