開始使用免費開始

建立直方圖

直方圖可以呈現單一變數的完整分佈。這個練習中,你會比較 2016 年奧運體操與划船項目得牌選手的體重分佈。

你會使用兩個 DataFrame。第一個名為 mens_rowing,包含男子划船項目得牌選手的資訊。另一個名為 mens_gymnastics,包含所有體操項目得牌選手的資訊。

本練習屬於課程

Matplotlib 資料視覺化入門

檢視課程

練習說明

  • 使用 ax.hist,把 mens_rowing DataFrame 中 "Weight" 欄位畫成直方圖。
  • 使用 ax.hist,把 mens_gymnastics"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()
編輯並執行程式碼