python绘制饼图explode_python通过matplotlib生成复合饼图

可以通过matplotlib实现

from matplotlib.patches import ConnectionPatch

#制画布fig = plt.figure(figsize=(9,5.0625))

ax1 = fig.add_subplot(121)

ax2 = fig.add_subplot(122)

fig.subplots_adjust(wspace=0)

#大饼图的制作

labels = newdata8.index

size = newdata8.quantity

explode=(0,0,0,0,0,0.1)

ax1.pie(size, autopct='%1.1f%%',startangle=30,labels=labels,explode=explode)

#小饼图的制作

labels2 = others.index

size2 = others.quantity

width=0.2

ax2.pie(size2, autopct='%1.1f%%',startangle=90,labels=labels2,

radius=0.5,shadow=True)

#使用ConnectionPatch画出两个饼图的间连线

#先得到饼图边缘的数据

theta1, theta2 = ax1.patches[5].theta1, ax1.patches[5].theta2

center, r = ax1.patches[5].center,ax1.patches[5].r

#画出上边缘的连线

x = r*np.cos(np.pi/180*theta2)+center[0]

y = np.sin(np.pi/180*theta2)+center[1]

con = ConnectionPatch(xyA=(-width/2,0.5),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=(-width/2,-0.5),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)plt.show()

输出:

blank.gif

图源数据为快餐店销量

总结

以上所述是小编给大家介绍的python通过matplotlib实现生成复合饼图,希望对大家有所帮助!

时间: 2020-02-04

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值