【发布时间】:2020-04-22 12:14:49
【问题描述】:
我正在尝试从导入的 CSV 文件 (data_dict) 的不同列中绘制直方图。我正在尝试解决下面的问题 - 当我输入以下代码时会出现轴,但是,绘图不会。我将如何绘制这些?非常感谢。
问题
编写代码,按年龄分别绘制女性和男性事故数量的直方图。使用 10 年的垃圾箱。在同一个图上绘制两个分布。
gender1 = np.array(data_dict['Gender'])
age1 = np.array(data_dict['Age'])
age_females = age1[np.where(gender1 == 'Female')]
age_males = age1[np.where(gender1 == 'Male')]
plt.hist(age_males,label='Males',alpha=0.5)
plt.hist(age_females,label='Females',alpha=0.5)
plt.legend()
plt.title('Histogram of Accidents by Age and Genders')
plt.xlabel('Age')
plt.ylabel('Accidents')
plt.xticks(ticks=np.arange(10,110,step=10),labels=(10,20,30,40,50,60,70,80,90,100))
print
【问题讨论】:
标签: python csv matplotlib