python 饼图笔记 两个饼图 双饼图 复合饼图 两个饼图 环形图 |
您所在的位置:网站首页 › 饼图交叉 › python 饼图笔记 两个饼图 双饼图 复合饼图 两个饼图 环形图 |
复合饼图
fig = plt.figure(figsize=(10,4))
ax1 = fig.add_subplot(121)
a = kcf.groupby('一级分类').总金额.sum().sort_values(ascending=False)
ax1.pie(a, labels=a.index, autopct='%.2f%%',startangle=-110, explode=[0,0.1],
colors=['#508cb4','#d7e4ef'])
plt.title('一级分类销售额分类汇总')
ax2 = fig.add_subplot(122)
a = kcf[kcf.一级分类=='饮料'].groupby('二级分类').总金额.sum().sort_values(ascending=False)
ax2.pie(a, radius=0.9, labels=a.index, autopct='%.2f%%', colors=['#265f95', '#508cb4', '#89b5ce', '#c5d8e7', '#e7eff7'])
plt.title('饮料品类下的销售额分类汇总')
#使用ConnectionPatch画出两个饼图的间连线
#先得到饼图边缘的数据
theta1, theta2 = ax1.patches[0].theta1+20, ax1.patches[0].theta2-20
center, r = ax1.patches[0].center,ax1.patches[0].r
x = r*np.cos(np.pi/180*theta2)+center[0]
y = np.sin(np.pi/180*theta2)+center[1]
con = ConnectionPatch(xyA=(0, 0.9),xyB=(x,y),
coordsA='data', coordsB='data',axesA=ax2,axesB=ax1)
con.set_linewidth(2)
con.set_color=([0,0,0])
ax2.add_artist(con)
#画出下边缘的连线
x = r*np.cos(np.pi/180*theta1)+center[0]
y = np.sin(np.pi/180*theta1)+center[1]
con = ConnectionPatch(xyA=(0,-0.9),xyB=(x,y),
coordsA='data', coordsB='data',axesA=ax2,axesB=ax1)
con.set_linewidth(2)
con.set_color=([0,0,0])
ax2.add_artist(con)
加入参数wedgeprops=dict(width=0.3, edgecolor='w') a = pe[pe.PID.isin(ksf.PID.drop_duplicates())].性别.value_counts() plt.pie(a, labels=a.index, autopct='%.1f%%', colors=['#8ebad9','#f1a4bd'], wedgeprops=dict(width=0.3, edgecolor='w'))参数 pctdistance 是数据标签离圆心的距离 ax2.pie(a, labels=a.index, autopct='%.1f%%',textprops=dict(fontsize=11), wedgeprops=dict(width=0.3, edgecolor='w'),pctdistance=0.55)
更改后: |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |