python利用matplotlib库绘制饼图的方法示例,pythonmatplotlib
python利用matplotlib库绘制饼图的方法示例,pythonmatplotlib
介绍
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合并字典键值并去除重复元素的实例,python字典
- python操作 hbase 数据的方法,pythonhbase
- python 调用HBase的简单实例,python调用hbase
- 更改Ubuntu默认python版本的两种方法python-> Anaconda,
- python虚拟环境virualenv的安装与使用,pythonvirualenv
- python用reduce和map把字符串转为数字的方法,pythonreduce
- python查看微信好友是否删除自己,python查看信好友
- 详解python中的json的基本使用方法,详解pythonjson
- Python 遍历子文件和所有子文件夹的代码实例,
- 使用Python3 编写简单信用卡管理程序,python3信用卡
评论关闭