Python matplotlib绘制饼状图功能示例
Python  /  管理员 发布于 8年前   260
本文实例讲述了Python matplotlib绘制饼状图功能。分享给大家供大家参考,具体如下:
一 代码
import numpy as npimport 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','#FF0000','lightcoral']#使饼状图中第2片和第4片裂开explode =(0,0.1,0,0.1)fig = plt.figure()ax = fig.gca()ax.pie(np.random.random(4), explode=explode, labels=labels, colors=colors,autopct='%1.1f%%', shadow=True, startangle=90,radius=0.25, center=(0,0), frame=True)ax.pie(np.random.random(4), explode=explode, labels=labels, colors=colors,autopct='%1.1f%%', shadow=True, startangle=90,radius=0.25, center=(1,1), frame=True)ax.pie(np.random.random(4), explode=explode, labels=labels, colors=colors,autopct='%1.1f%%', shadow=True, startangle=90,radius=0.25, center=(0,1), frame=True)ax.pie(np.random.random(4), explode=explode, labels=labels, colors=colors,autopct='%1.1f%%', shadow=True, startangle=90,radius=0.25, center=(1,0), frame=True)#设置坐标轴刻度ax.set_xticks([0,1])ax.set_yticks([0,1])#设置坐标轴刻度上显示的标签ax.set_xticklabels(["Sunny","Cloudy"])ax.set_yticklabels(["Dry","Rainy"])#设置坐标轴跨度ax.set_xlim((-0.5,1.5))ax.set_ylim((-0.5,1.5))#设置纵横比相等ax.set_aspect('equal')plt.show()二 运行结果
更多关于Python相关内容感兴趣的读者可查看本站专题:《Python数学运算技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》及《Python入门与进阶经典教程》
希望本文所述对大家Python程序设计有所帮助。
test1 在
opencode + Oh-my-openagent,我的第一个免费的ai编程智能体管家:Sisyphus中评论 test..122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..Zita 在
Google AI Studio升级全栈 vibe coding体验,可直接构建带登录和数据库的应用中评论 111222..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号
