【发布时间】:2020-07-12 14:50:17
【问题描述】:
我使用 agg 来查找按年龄分组的平均值和最小值。然后尝试绘制区域填充折线图。
grpby = df6.groupby('age')
mean_values = grpby.agg({'hoursperweek':np.mean})
min_values = grpby.agg({'hoursperweek':np.min})
from matplotlib import pyplot as plt
plt.plot(mean_values,label = 'mean')
plt.plot(min_values,label = 'min',linestyle = '--')
plt.fill_between(mean_values,alpha = 0.25)
plt.legend()
plt.title('Mean and min')
plt.xlabel('ages')
plt.ylabel('hrs per week')
plt.show()
我的平均值输出:
hoursperweek
age
31 42.877252
32 42.878019
33 42.965714
34 42.937923
35 43.908676
36 43.257238
37 43.706294
...
...
我收到以下错误
plt.fill_between(mean_values,alpha = 0.25)
TypeError: fill_between() missing 1 required positional argument: 'y1'
如何解决?
【问题讨论】:
标签: python pandas dataframe matplotlib