python利用matplotlib库绘制饼图的方法示例
作者:jihite 时间:2022-12-17 15:16:50
介绍
matplotlib 是python最著名的绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地进行制图。而且也可以方便地将它作为绘图控件,嵌入GUI应用程序中。
它的文档相当完备,并且 Gallery页面 中有上百幅缩略图,打开之后都有源程序。因此如果你需要绘制某种类型的图,只需要在这个页面中浏览/复制/粘贴一下,基本上都能搞定。
matplotlib的安装方法可以点击这里
这篇文章给大家主要介绍了python用matplotlib绘制饼图的方法,话不多说,下面来看代码。
示例代码
import matplotlib.pyplot as plt
# The slices will be ordered and plotted counter-clockwise.
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
sizes = [15, 30, 45, 10]
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']
explode = (0, 0.1, 0, 0) # only "explode" the 2nd slice (i.e. 'Hogs')
plt.pie(sizes, explode=explode, labels=labels, colors=colors,
autopct='%1.1f%%', shadow=True, startangle=90)
# Set aspect ratio to be equal so that pie is drawn as a circle.
plt.axis('equal')
plt.savefig('D:\\pie.png')
plt.show()
结果
总结
标签:python,matplotlib,饼图
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python用字符组成图像代码实例
2023-09-15 02:12:04
![](https://img.aspxhome.com/file/2023/7/62597_0s.jpg)
Python3.8 + Tkinter: Button设置image属性不显示的问题及解决方法
2021-08-12 00:40:33
![](https://img.aspxhome.com/file/2023/2/95392_0s.png)
Python算法应用实战之栈详解
2022-08-22 21:56:10
![](https://img.aspxhome.com/file/2023/7/69547_0s.png)
python实现划词翻译
2023-04-28 19:36:54
![](https://img.aspxhome.com/file/2023/1/84131_0s.jpg)
3个常用的JS时间代码
2009-03-22 15:29:00
PHP5 mysqli的prepare准备语句使用说明
2023-11-22 12:50:29
7个流行的Python强化学习算法及代码实现详解
2021-07-06 08:38:03
动态提示的select下拉框
2007-12-02 14:54:00
Python tkinter常用操作代码实例
2021-01-05 21:26:09
python工具——Mimesis的简单使用教程
2021-08-06 07:27:23
![](https://img.aspxhome.com/file/2023/8/80618_0s.png)
asp Response.flush 实时显示进度
2011-04-14 10:31:00
Python高级架构模式知识点总结
2023-12-19 14:36:47
django项目简单调取百度翻译接口的方法
2023-10-20 18:25:41
![](https://img.aspxhome.com/file/2023/0/64280_0s.png)
python3音乐播放器简单实现代码
2022-06-12 04:43:14
Python 函数装饰器应用教程
2022-08-17 05:53:24
Python3列表删除的三种方式实现
2021-03-26 17:55:55
![](https://img.aspxhome.com/file/2023/5/89305_0s.jpg)
python实现登录密码重置简易操作代码
2022-12-08 13:34:43
Mysql数据库名和表名的大小写敏感性问题
2010-06-07 14:07:00
python内建类型与标准类型
2021-06-03 19:47:45
![](https://img.aspxhome.com/file/2023/7/64707_0s.png)
Python脚本实现格式化css文件
2023-01-09 19:00:37