建立直方圖
直方圖可以呈現單一變數的完整分佈。這個練習中,你會比較 2016 年奧運體操與划船項目得牌選手的體重分佈。
你會使用兩個 DataFrame。第一個名為 mens_rowing,包含男子划船項目得牌選手的資訊。另一個名為 mens_gymnastics,包含所有體操項目得牌選手的資訊。
本練習屬於課程
Matplotlib 資料視覺化入門
練習說明
- 使用
ax.hist,把mens_rowingDataFrame 中"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()