建立並解讀箱形圖
讓我們繼續使用 student_data 資料集。在前一個練習中,你用長條圖比較不同 "study_time" 類別之間的平均期末成績("G3"),來探索讀書時間與期末成績的關係。
在這個練習中,我們改用箱形圖來觀察這個關係。提醒你,若要建立箱形圖,需要使用 catplot() 函式,並指定要放在 x 軸的類別變數名稱(x=____)、要在 y 軸彙整的量化變數名稱(y=____)、要使用的 pandas DataFrame(data=____),以及圖形的種類(kind="box")。
我們已經將 matplotlib.pyplot 以 plt 匯入,並將 seaborn 以 sns 匯入。
本練習屬於課程
Seaborn 資料視覺化入門
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Specify the category ordering
study_time_order = ["<2 hours", "2 to 5 hours",
"5 to 10 hours", ">10 hours"]
# Create a box plot and set the order of the categories
# Show plot
plt.show()