用兩個 KDE 比較
想像你在一家頂尖的空氣濾淨器公司任職。公司要你製作一份報告,說明為什麼 2012 年是臭氧(O3)濾心銷售特別好的年份。你從 USGS 下載了有用的污染資料,並想做一張精簡的視覺化,把 2012 年的 O3 汙染整體分布與其他年份做比較。
為了達成這個目標,你可以疊加兩張核心密度估計圖(KDE):一張用 2012 的 O3 資料,另一張用所有其他年份的資料。
本練習屬於課程
用 Python 改善你的資料視覺化
練習說明
- 在第一次呼叫
sns.kdeplot()時,先篩選資料,只包含年份為2012。 - 使用
shade參數為第一個 KDE 的曲線下方上色。 - 為圖例加入標籤
'2012'。 - 對第二次
sns.kdeplot()呼叫重複上述三個步驟,但將資料篩選為不包含2012。圖例標籤使用'other years'。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Filter dataset to the year 2012
sns.kdeplot(pollution[pollution.year ____ ____].O3,
# Shade under kde and add a helpful label
shade = ____,
____ = '____')
# Filter dataset to everything except the year 2012
sns.kdeplot(pollution[pollution.year ____ ____].O3,
# Again, shade under kde and add a helpful label
shade = ____,
____ = '____')
plt.show()