matplotlib绘制饼状图

匿名 (未验证) 提交于 2019-12-02 23:42:01

1、普通的饼状图

from matplotlib import pyplot as plt  # 显示饼状图 # label = ["test1","test2","test3","test4"] # # fracs = [20,30,40,10] # # plt.axes(aspect=2) # plt.pie(labels=label,x=fracs) # plt.show() 

2、显示每个label的比例

# 在图例中显示每个label的比例 # label = ["test1","test2","test3","test4"] # # fracs = [20,30,40,10] # # plt.axes(aspect=2) # plt.pie(labels=label,x=fracs,autopct="%.0f%%") # plt.show() 

3、可以让某个/某几个label离开圆柱体,可以设置距离,如果不离开,距离设置为0即可

# # 可以让某个标签离开圆柱体 # label = ["test1","test2","test3","test4"] # fracs = [20,30,40,10] # # # 这里的0.1和0.2就是离开的距离 # explode = [0,0.1,0,0.2] # plt.axes(aspect=2) # plt.pie(labels=label,x=fracs,autopct="%.0f%%",explode=explode) # plt.show() 

4、设置阴影效果

# 可以让某个标签离开圆柱体 # label = ["test1","test2","test3","test4"] # fracs = [20,30,40,10] # # # 这里的0.1和0.2就是离开的距离 # explode = [0,0.1,0,0.2] # plt.axes(aspect=2) # # shadow设置阴影效果 # plt.pie(labels=label,x=fracs,autopct="%.0f%%",explode=explode,shadow=True) # plt.show() 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!