Hue 與 count plot
讓我們繼續探索國高中生的資料集,看看一個新的變數。"school" 欄位表示學生就讀學校的縮寫,可能是 "GP" 或 "MS"。
在上一個練習中,我們建立了散佈圖,並依據學生居住在都市或鄉村來著色。究竟有多少學生住在都市與鄉村?這會隨著學生就讀的學校而改變嗎?讓我們建立一個帶有子群組的計數圖來找出答案。
本練習屬於課程
Seaborn 資料視覺化入門
練習說明
- 完成
palette_colors字典,將地點值"Rural"對應為"green","Urban"對應為"blue"。 - 使用
student_dataDataFrame 建立一個以"school"為 x 軸的計數圖。- 使用變數
"location"為圖表加入子群組,並使用palette_colors字典將地點子群組分別設為綠色與藍色。
- 使用變數
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import Matplotlib and Seaborn
import matplotlib.pyplot as plt
import seaborn as sns
# Create a dictionary mapping subgroup values to colors
palette_colors = {____: "green", ____: "blue"}
# Create a count plot of school with location subgroups
# Display plot
plt.show()