溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

python通過(guò)matplotlib生成復(fù)合餅圖

發(fā)布時(shí)間:2020-09-25 19:09:03 來(lái)源:腳本之家 閱讀:192 作者:imakeithappen 欄目:開(kāi)發(fā)技術(shù)

可以通過(guò)matplotlib實(shí)現(xiàn)

from matplotlib.patches import ConnectionPatch
#制畫(huà)布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畫(huà)出兩個(gè)餅圖的間連線
#先得到餅圖邊緣的數(shù)據(jù)
theta1, theta2 = ax1.patches[5].theta1, ax1.patches[5].theta2
center, r = ax1.patches[5].center,ax1.patches[5].r
#畫(huà)出上邊緣的連線
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)
#畫(huà)出下邊緣的連線
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()

輸出:

python通過(guò)matplotlib生成復(fù)合餅圖

圖源數(shù)據(jù)為快餐店銷(xiāo)量

總結(jié)

以上所述是小編給大家介紹的python通過(guò)matplotlib實(shí)現(xiàn)生成復(fù)合餅圖,希望對(duì)大家有所幫助!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI