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()

 

效果图如下

 

posted on 2019-06-13 09:21  bainianminguo  阅读(731)  评论(0编辑  收藏  举报