欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python matplotlib繪制餅狀圖功能示例

 更新時間:2019年09月10日 11:40:41   作者:cakincqm  
這篇文章主要介紹了Python matplotlib繪制餅狀圖功能,結(jié)合實例形式分析了Python使用matplotlib模塊進(jìn)行數(shù)值運算與餅狀圖繪制相關(guān)操作技巧,需要的朋友可以參考下

本文實例講述了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)
#設(shè)置坐標(biāo)軸刻度
ax.set_xticks([0,1])
ax.set_yticks([0,1])
#設(shè)置坐標(biāo)軸刻度上顯示的標(biāo)簽
ax.set_xticklabels(["Sunny","Cloudy"])
ax.set_yticklabels(["Dry","Rainy"])
#設(shè)置坐標(biāo)軸跨度
ax.set_xlim((-0.5,1.5))
ax.set_ylim((-0.5,1.5))
#設(shè)置縱橫比相等
ax.set_aspect('equal')
plt.show()

二 運行結(jié)果

更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python數(shù)學(xué)運算技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》及《Python入門與進(jìn)階經(jīng)典教程

希望本文所述對大家Python程序設(shè)計有所幫助。

相關(guān)文章

最新評論