開始使用免費開始

含子群組的箱形圖

在這個練習中,我們要查看一個關於年輕人問卷回應的資料集。其中一個問題是:「你對養寵物有興趣嗎?」我們來探索,在控制性別之下,回答「yes」的受訪者年齡分佈,相較於回答「no」者,是否傾向較高或較低。

本練習屬於課程

Seaborn 資料視覺化入門

檢視課程

練習說明

  • 將色盤設為 "Blues"
  • 加入子群組,依據 "Interested in Pets" 為箱形圖著色。
  • FacetGrid 物件 g 的標題設為 "Age of Those Interested in Pets vs. Not"
  • 使用 Matplotlib 的函式來顯示圖表。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Set palette to "Blues"
____

# Adjust to add subgroups based on "Interested in Pets"
g = sns.catplot(x="Gender",
                y="Age", data=survey_data, 
                kind="box", hue=____)

# Set title to "Age of Those Interested in Pets vs. Not"
____

# Show plot
plt.____
編輯並執行程式碼