開始使用免費開始

含子群與子圖的長條圖

在這個練習中,我們會回到年輕族群的問卷資料集,來探查喜歡電子舞曲("Likes Techno")的比例,是否會因性別("Gender")或居住地("Village - town")而不同。這個練習能讓你綜合練習本課程中學到的重點!

我們已經將 Seaborn 以 sns 匯入,並將 matplotlib.pyplotplt 匯入。

本練習屬於課程

Seaborn 資料視覺化入門

檢視課程

練習說明

  • 將圖形樣式設定為 "dark"
  • 調整長條圖的程式碼,依 "Gender" 加入以欄排列的子圖。
  • 在這個 FacetGrid 圖上加入標題:"Percentage of Young People Who Like Techno"
  • 將 x 軸標記為 "Location of Residence",y 軸標記為 "% Who Like Techno"

動手互動練習

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

# Set the figure style to "dark"
____

# Adjust to add subplots per gender
g = sns.catplot(x="Village - town", y="Likes Techno", 
                data=survey_data, kind="bar",
                ____)

# Add title and axis labels
g.____("Percentage of Young People Who Like Techno", y=1.02)
g.____(____="Location of Residence", 
       ____="% Who Like Techno")

# Show plot
plt.show()
編輯並執行程式碼