蜂群圖(Bee swarm plot)
請為鳶尾花(iris)的花瓣長度製作一張蜂群圖。x 軸放 3 個品種,y 軸放花瓣長度。包含資料的 DataFrame 已以 df 放在你的命名空間中。
提供你參考,以下是 Justin 在影片中用來建立蜂群圖的程式碼:
_ = sns.swarmplot(x='state', y='dem_share', data=df_swing)
_ = plt.xlabel('state')
_ = plt.ylabel('percent of vote for Obama')
plt.show()
你可以使用 help(sns.swarmplot) 來瞭解更多如何用 seaborn 製作蜂群圖的細節。
本練習屬於課程
Statistical Thinking in Python (Part 1)
練習說明
- 使用
df.head()檢視 DataFramedf。這能讓你確認在呼叫sns.swarmplot()時,該把哪些欄位名稱分別傳入x與y關鍵字參數。 - 使用
sns.swarmplot(),從包含 Fisher 鳶尾花資料集的 DataFrame(df)繪製蜂群圖。x 軸應包含 3 個品種,y 軸應包含花瓣長度。 - 為座標軸加上標籤。
- 顯示你的圖表。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create bee swarm plot with Seaborn's default settings
# Label the axes
# Show the plot