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()
二 运行结果
mapplotlib绘制饼状图_第1张图片
 
  • mapplotlib绘制饼状图_第2张图片
  • 大小: 45 KB
  • 查看图片附件

你可能感兴趣的:(mapplotlib,饼状图)