python 画图--饼图
来源:互联网 发布:php类与对象person 编辑:程序博客网 时间:2024/05/22 03:15
python 画图--饼图
这是Python画图系列第三篇--饼图
画饼图用到的方法为:
matplotlib.pyplot.
pie
()
参数为:
参数说明:
返回值:
如果没有设置autopct,返回(patches, texts)
如果设置autopct,返回(patches, texts, autotexts)
patches -- list --matplotlib.patches.Wedge对象
texts autotexts -- matplotlib.text.Text对象
下面是一个简单的示例:
下面是结果:
下面是另一个示例:
官方文档:
链接:http://matplotlib.org/api/pyplot_api.html
matplotlib.pyplot.
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, hold=None, data=None)Plot a pie chart.
Call signature:
pie(x, explode=None, labels=None, colors=('b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'), 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 )
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 wedges are plotted counterclockwise, by default starting from the x-axis.
Keyword arguments:
- explode: [ None | len(x) sequence ]
- If not None, is a
len(x)
array which specifies the fraction of the radius with which to offset each wedge.- colors: [ None | color sequence ]
- A sequence of matplotlib color args through which the pie chart will cycle.
- labels: [ None | len(x) sequence of strings ]
- A sequence of strings providing the labels for each wedge
- autopct: [ None | format string | format function ]
- 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.- pctdistance: scalar
- The ratio between the center of each pie slice and the start of the text generated by autopct. Ignored if autopct is None; default is 0.6.
- labeldistance: scalar
- The radial distance at which the pie labels are drawn
- shadow: [ False | True ]
- Draw a shadow beneath the pie.
- startangle: [ None | Offset angle ]
- If not None, rotates the start of the pie chart by angle degrees counterclockwise from the x-axis.
radius: [ None | scalar ] The radius of the pie, if radius is None it will be set to 1.
- counterclock: [ False | True ]
- Specify fractions direction, clockwise or counterclockwise.
- wedgeprops: [ None | dict of key value pairs ]
- 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
.- textprops: [ None | dict of key value pairs ]
- Dict of arguments to pass to the text objects.
center: [ (0,0) | sequence of 2 scalars ] Center position of the chart.
- frame: [ False | True ]
- Plot axes frame with the chart.
The pie chart will probably look best if the figure and axes are square, or the Axes aspect is equal. e.g.:
figure(figsize=(8,8))ax = axes([0.1, 0.1, 0.8, 0.8])
or:
axes(aspect=1)
- Return value:
If autopct is None, return the tuple (patches, texts):
- patches is a sequence of
matplotlib.patches.Wedge
instances - texts is a list of the label
matplotlib.text.Text
instances.
If autopct is not None, return the tuple (patches, texts, autotexts), where patches and texts are as above, and autotexts is a list of
Text
instances for the numeric labels.- patches is a sequence of
Notes
In addition to the above described arguments, this function can take a data keyword argument. If such a data argument is given, the following arguments are replaced by data[<arg>]:
- All arguments with the following names: ‘colors’, ‘x’, ‘explode’, ‘labels’.
Additional kwargs: hold = [True|False] overrides default hold state
- python 画图--饼图
- python 画图--饼图
- python 画图
- Python 画图
- Python画图
- python画图
- python画图
- Python 画图
- python画图
- Python 画图
- python 画图
- python 画图
- python画图
- Python 画图
- python画图
- python画图
- Python 画图
- Python画图
- ALSA --- amixer控制声卡驱动实现Line-in功能
- 关于AppSplash启动优化
- tomcat启动寻找JAVA环境
- 【随笔】关于坚持
- elasticsearch 查询(match和term)
- python 画图--饼图
- Stuts2国际化
- 支持POST方式的webbench
- Vue.js学习系列(二十五)-- 循环语句(一)
- 排序-插入排序
- MySQL 最最简单命令---- 慢慢收集
- 区块链学堂(第三课):以太坊生产网络/测试网络/私有网络+Geth 搭建私有网络实战
- MySQL权限
- uml在线画图共享网站