盒鬚圖(Box-and-whisker plot)
對花瓣長度繪製盒鬚圖不是必要的,因為 iris 資料集不大,而且蜂群圖已經足夠。不過,多練習總是好的。請為 iris 的花瓣長度繪製盒鬚圖。你的命名空間中有一個 pandas DataFrame df,其中包含花瓣長度資料。先用 df.head() 檢視 df,確認相關欄位名稱。
供你參考,影片中產生盒鬚圖所用的程式碼如下:
_ = sns.boxplot(x='east_west', y='dem_share', data=df_all_states)
_ = plt.xlabel('region')
_ = plt.ylabel('percent of vote for Obama')
你可以使用 sns.boxplot? 或 help(sns.boxplot) 以取得更多關於如何用 seaborn 繪製盒鬚圖的說明。
本練習屬於課程
Statistical Thinking in Python (Part 1)
練習說明
- 設定方式與蜂群圖完全相同;只需呼叫
sns.boxplot(),並使用與sns.swarmplot()相同的關鍵字引數。x 軸為'species',y 軸為'petal length (cm)'。 - 別忘了替座標軸加上標籤!
- 以一般方式顯示圖形。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create box plot with Seaborn's default settings
# Label the axes
# Show the plot