开始使用免费开始使用

绘制直方图

直方图可以展示变量的完整分布。本练习中,您将对比显示 2016 年奥运会上体操与赛艇奖牌获得者的体重分布。

您将使用两个 DataFrame。第一个名为 mens_rowing,包含男子赛艇项目奖牌获得者的信息。另一个名为 mens_gymnastics,包含所有体操项目奖牌获得者的信息。

本练习是课程的一部分

Matplotlib 数据可视化入门

查看课程

练习说明

  • 使用 ax.hist 方法,为 mens_rowing DataFrame 的 "Weight" 列添加一个直方图。
  • 使用 ax.hist,为 mens_gymnastics DataFrame 的 "Weight" 列添加一个直方图。
  • 将 x 轴标签设为 "Weight (kg)",y 轴标签设为 "# of observations"

交互式实操练习

通过完成这段示例代码来试试这个练习。

fig, ax = plt.subplots()
# Plot a histogram of "Weight" for mens_rowing
ax.hist(____)

# Compare to histogram of "Weight" for mens_gymnastics
____

# Set the x-axis label to "Weight (kg)"
____

# Set the y-axis label to "# of observations"
____

plt.show()
编辑并运行代码