Python-Matplotlib 7 餅狀圖
Example 1
import numpy as np
import matplotlib.pyplot as plt
labels = 'A', 'B', 'C', 'D'
fracs = [15, 30.55, 44.44, 10]
explode = [0, 0.1, 0, 0] # 0.1 凸出這部分,
plt.axes(aspect=1) # set this , Figure is round, otherwise it is an ellipse
#autopct ,show percet
plt.pie(x=fracs, labels=labels, explode=explode,autopct='%3.1f %%',
shadow=True, labeldistance=1.1, startangle = 90,pctdistance = 0.6
)
'''
labeldistance,文本的位置離遠點有多遠,1.1指1.1倍半徑的位置
autopct,圓里面的文本格式,%3.1f%%表示小數有三位,整數有一位的浮點數
shadow,餅是否有陰影
startangle,起始角度,0,表示從0開始逆時針轉,為第一塊。一般選擇從90度開始比較好看
pctdistance,百分比的text離圓心的距離
patches, l_texts, p_texts,為了得到餅圖的返回值,p_texts餅圖內部文本的,l_texts餅圖外label的文本
'''
plt.show()
