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')
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()
|