在使用python时绘制饼图,legend代码部分出现了问题
'list' object is not callable
import matplotlib.pyplot as plt
from pylab import mpl
mpl.rcParams['font.sans-serif'] = ['Microsoft YaHei']
mpl.rcParams['axes.unicode_minus'] = False
#定义变量
num = [20, 30, 40, 50]
grade = ['grade_1', 'grade_2', 'grade_3', 'grade_4']
colors = ['orange', 'green', 'red', 'blue']
explode = (0.10, 0, 0, 0)
plt.axis('equal')#保证是一个圆形,而不是椭圆
plt.title("各年级人数", fontsize = 20, color ='k')
plt.pie(num, explode = explode, colors = colors, autopct = '%.2f%%',
shadow = False, pctdistance = 0.6, startangle = 0)
plt.legend(['grade_1', 'grade_2', 'grade_3', 'grade_4'])