以百分比呈現的長條圖
讓我們繼續探索發給年輕族群的問卷回覆。變數 "Interested in Math" 若為 True,表示受訪者自述對數學「有興趣」或「非常有興趣」;否則為 False。有多少比例的年輕人表示對數學有興趣?這會因性別而有所不同嗎?讓我們用長條圖來找答案。
提醒一下,我們會使用 catplot() 函式建立長條圖,並提供要放在 x 軸的類別變數名稱(x=____)、要在 y 軸彙總的數值變數名稱(y=____)、要使用的 pandas DataFrame(data=____),以及類別圖的型式(kind="bar")。
已經將 Seaborn 載入為 sns,並將 matplotlib.pyplot 載入為 plt。
本練習屬於課程
Seaborn 資料視覺化入門
練習說明
- 使用
survey_dataDataFrame 與sns.catplot(),建立以"Gender"為 x 軸、"Interested in Math"為 y 軸的長條圖。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create a bar plot of interest in math, separated by gender
# Show plot
plt.show()