2019-09-10 13:45:25 5250瀏覽
今天千鋒扣丁學堂Python培訓老師給大家分享一篇關(guān)于matplotlib繪制餅狀圖功能示例的詳細介紹,結(jié)合實例形式分析了Python使用matplotlib模塊進行數(shù)值運算與餅狀圖繪制相關(guān)操作技巧,下面我們一起來看一下吧。
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()
【關(guān)注微信公眾號獲取更多學習資料】 【掃碼進入Python全棧開發(fā)免費公開課】
查看更多關(guān)于"Python開發(fā)資訊"的相關(guān)文章>