14 python数据可视化(精讲饼图)
00 载入扩展库
import numpy as np
import matplotlib.pyplot as plt
01 饼图
x=[15, 30, 20, 35]
label=['Frogs', 'Hogs', 'Dogs', 'Logs']
plt.pie(x,autopct='%.2f%%', labels=label,startangle=45)
02 分裂饼图
x=[15, 30, 20, 35]
label=['Frogs', 'Hogs', 'Dogs', 'Logs']
explode = [0, 0.1, 0, 0.2]
plt.pie(x,autopct='%.2f%%',explode=explode, labels=label,startangle=45)
03 改变饼图文字位置
x=[15, 30, 20, 35]
label=['Frogs', 'Hogs', 'Dogs', 'Logs']
explode = [0, 0.1, 0, 0]
plt.pie(x,autopct='%.0f%%',explode=explode, labels=label,startangle=45,
pctdistance=0.4,labeldistance=0.9)
04 改变饼图属性
x=[15, 30, 20, 35]
plt.pie(x,autopct='%.0f%%',
textprops=dict(color='w',size=15,weight='bold' ))
05 环形图
x=[15,30,20,35]
plt.pie(x,autopct='%.0f%%',radius=1,pctdistance=0.85,
wedgeprops=dict(width=0.3,edgecolor='k'))
06 综合实例
x=[15,30,20,35]
y=[10,20,30,40]
plt.pie(x,autopct='%.0f%%',radius=1,pctdistance=0.85,
textprops=dict(color='w'),wedgeprops=dict(width=0.3,edgecolor='k'))
plt.pie(y,autopct='%.0f%%',radius=0.7,pctdistance=0.55,
textprops=dict(color='b'),wedgeprops=dict(width=0.5,edgecolor='w'))