餅圖
餅圖是一個劃分為幾個扇形的圓形統計圖表,用于描述量、頻率或百分比之間的相對關系的, 在matplotlib中,可以通過plt.pie來實作,其中的引數如下:
x:餅圖的比例序列,labels:餅圖上每個分塊的名稱文字,explode:設定某幾個分塊是否要分離餅圖,autopct:設定比例文字的展示方式,比如保留幾個小數等,shadow:是否顯示陰影,textprops:文本的屬性(顏色,大小等),- 其他引數:https://matplotlib.org/api/_as_gen/matplotlib.pyplot.pie.html#matplotlib.pyplot.pie
回傳值:
patches:餅圖上每個分塊的物件,texts:分塊的名字文本物件,autotexts:分塊的比例文字物件,
假如現在我們有一組資料,用來記錄各個作業系統的市場份額的,那么用餅狀圖表示如下:
oses = { 'windows7':60.86, 'windows10': 18.46, 'windows8': 3.61, 'windows xp': 10.3, 'mac os': 6.78, '其他': 1.12 } names = oses.keys() percents = oses.values() patches,texts,autotexts = plt.pie(percents,labels=names,autopct="%.2f%%",explode=(0,0.05,0,0,0,0)) for text in texts+autotexts: plt.setp(text,fontproperties=font) text.set_fontsize(10) for text in autotexts: text.set_color("white")
效果圖如下:
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/276911.html
標籤:Python
上一篇:如何利用ipad隨時隨地開發代碼
