蜂群圖(Beeswarms)
使用 sns.swarmplot() 建立一個蜂群圖,呈現 pollution 資料中 3 月各城市的 Ozone(臭氧)濃度。為了讓圖形更容易閱讀,請縮小點的大小,以避免螢幕上過多點造成擁擠。最後,因為你為了繪圖對資料做了一些處理,請加上標題,幫助讀者理解他們正在看的內容。
本練習屬於課程
用 Python 改善你的資料視覺化
練習說明
- 將
pollution資料子集化為只包含 3 月的觀測值。 - 在
swarmplot()中將O3濃度作為連續數值來繪製。 - 將點大小調整為
3,以避免點過於擁擠。 - 將圖表標題設為 'March Ozone levels by city'。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Filter data to just March
pollution_mar = pollution[pollution.month == ____]
# Plot beeswarm with x as O3
sns.swarmplot(y = "city",
x = '____',
data = pollution_mar,
# Decrease the size of the points to avoid crowding
size = ____)
# Give a descriptive title
plt.____('____')
plt.show()