1. 程式人生 > >matplotlib之餅狀圖

matplotlib之餅狀圖

import matplotlib.pyplot as plt


labels = 'A', 'B', 'C', 'D'
fracs = [35, 20, 45, 10]

plt.pie(x=fracs, labels=labels)
plt.show()

圓形餅圖

import matplotlib.pyplot as plt


labels = 'A', 'B', 'C', 'D'
fracs = [35, 20, 45, 10]

plt.axes(aspect=1)
plt.pie(x=fracs, labels=labels)
plt.show()

比例顯示

import matplotlib.pyplot as plt


labels = 'A', 'B', 'C', 'D'
fracs = [35, 20, 45, 10]

plt.axes(aspect=1)
plt.pie(x=fracs, labels=labels, autopct='%.0f%%')
plt.show()

突出顯示

import matplotlib.pyplot as plt


labels = 'A', 'B', 'C', 'D'
fracs = [35, 20, 45, 10]
explode = [0, 0.05, 0.08, 0]

plt.axes(aspect=1)
plt.pie(x=fracs, labels=labels, autopct='%.0f%%', explode=explode)
plt.show()

新增陰影

import matplotlib.pyplot as plt


labels = 'A', 'B', 'C', 'D'
fracs = [35, 20, 45, 10]
explode = [0, 0.05, 0.08, 0]

plt.axes(aspect=1)
plt.pie(x=fracs, labels=labels, autopct='%.0f%%', explode=explode, shadow=True)
plt.show()