我是靠谱客的博主 拼搏皮皮虾,这篇文章主要介绍mapplotlib绘制饼状图,现在分享给大家,希望可以做个参考。

一 代码

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. #The slices will be ordered and plotted counter-clockwise.
  4. labels ='Frogs','Hogs','Dogs','Logs'
  5. sizes =[15,30,45,10]
  6. colors =['yellowgreen','gold','#FF0000','lightcoral']
  7. #使饼状图中第2片和第4片裂开
  8. explode =(0,0.1,0,0.1)
  9. fig = plt.figure()
  10. ax = fig.gca()
  11. ax.pie(np.random.random(4), explode=explode, labels=labels, colors=colors,
  12. autopct='%1.1f%%', shadow=True, startangle=90,
  13. radius=0.25, center=(0,0), frame=True)
  14. ax.pie(np.random.random(4), explode=explode, labels=labels, colors=colors,
  15. autopct='%1.1f%%', shadow=True, startangle=90,
  16. radius=0.25, center=(1,1), frame=True)
  17. ax.pie(np.random.random(4), explode=explode, labels=labels, colors=colors,
  18. autopct='%1.1f%%', shadow=True, startangle=90,
  19. radius=0.25, center=(0,1), frame=True)
  20. ax.pie(np.random.random(4), explode=explode, labels=labels, colors=colors,
  21. autopct='%1.1f%%', shadow=True, startangle=90,
  22. radius=0.25, center=(1,0), frame=True)
  23. #设置坐标轴刻度
  24. ax.set_xticks([0,1])
  25. ax.set_yticks([0,1])
  26. #设置坐标轴刻度上显示的标签
  27. ax.set_xticklabels(["Sunny","Cloudy"])
  28. ax.set_yticklabels(["Dry","Rainy"])
  29. #设置坐标轴跨度
  30. ax.set_xlim((-0.5,1.5))
  31. ax.set_ylim((-0.5,1.5))
  32. #设置纵横比相等
  33. ax.set_aspect('equal')
  34. plt.show()
二 运行结果

 
  • 大小: 45 KB
  • 查看图片附件

最后

以上就是拼搏皮皮虾最近收集整理的关于mapplotlib绘制饼状图的全部内容,更多相关mapplotlib绘制饼状图内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(125)

评论列表共有 0 条评论

立即
投稿
返回
顶部