matplotlib.pyplot.pie

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""
demo03_pie.py 饼状图
"""
import numpy as np
import matplotlib.pyplot as plt

# 整理数据
labels = ['Python', 'JavaScript',
'C++', 'Java', 'PHP']
values = [26, 17, 21, 29, 11]
spaces = [0.05, 0.01, 0.01, 0.01, 0.01]
colors = ['dodgerblue', 'orangered',
'limegreen', 'violet', 'gold']
plt.figure('pie', facecolor='lightgray')
# title 不显示中文
plt.title(r'Pie Figure')
# 等轴比例
plt.axis('equal')
plt.pie(values, spaces, labels, colors, '%.2f%%',
shadow=True, startangle=0, radius=1)
plt.savefig('Pie.png')
plt.show()

Figure Pie