長條圖
長條圖會將依類別整理的資料,以一系列長條呈現;每個長條的高度代表該類別中的資料數值。
在這個練習中,你會用提供的 medals DataFrame 視覺化各國獲得金牌的數量。這個 DataFrame 以國家作為索引,並有一個名為 "Gold" 的欄,依各列紀錄每個國家贏得的金牌數。
本練習屬於課程
Matplotlib 資料視覺化入門
練習說明
- 呼叫
ax.bar方法,將"Gold"欄位依國家繪製成圖。 - 使用
ax.set_xticklabels,把 x 軸刻度標籤設為各國名稱。 - 在呼叫
ax.set_xticklabels時,使用rotation參數將 x 軸刻度標籤旋轉 90 度。 - 將 y 軸標籤設為
"Number of medals"。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
fig, ax = plt.subplots()
# Plot a bar-chart of gold medals as a function of country
____
# Set the x-axis tick labels to the country names
____.set_xticklabels(____, ____)
# Set the y-axis label
____
plt.show()