本文實例講述了Python matplotlib繪制餅狀圖功能。分享給大家供大家參考,具體如下:
一 代碼
import numpy as np import matplotlib.pyplot as plt #The slices will be ordered and plotted counter-clockwise. labels ='Frogs','Hogs','Dogs','Logs' sizes =[15,30,45,10] colors =['yellowgreen','gold','#FF0000','lightcoral'] #使餅狀圖中第2片和第4片裂開 explode =(0,0.1,0,0.1) fig = plt.figure() ax = fig.gca() ax.pie(np.random.random(4), explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', shadow=True, startangle=90, radius=0.25, center=(0,0), frame=True) ax.pie(np.random.random(4), explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', shadow=True, startangle=90, radius=0.25, center=(1,1), frame=True) ax.pie(np.random.random(4), explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', shadow=True, startangle=90, radius=0.25, center=(0,1), frame=True) ax.pie(np.random.random(4), explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', shadow=True, startangle=90, radius=0.25, center=(1,0), frame=True) #設置坐標軸刻度 ax.set_xticks([0,1]) ax.set_yticks([0,1]) #設置坐標軸刻度上顯示的標簽 ax.set_xticklabels(["Sunny","Cloudy"]) ax.set_yticklabels(["Dry","Rainy"]) #設置坐標軸跨度 ax.set_xlim((-0.5,1.5)) ax.set_ylim((-0.5,1.5)) #設置縱橫比相等 ax.set_aspect('equal') plt.show()
二 運行結果
更多關于Python相關內容感興趣的讀者可查看本站專題:《Python數學運算技巧總結》、《Python數據結構與算法教程》、《Python函數使用技巧總結》、《Python字符串操作技巧匯總》及《Python入門與進階經典教程》
希望本文所述對大家Python程序設計有所幫助。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
