Seaborn 資料視覺化入門
Content Team
DataCamp
匯入 Seaborn:
import seaborn as sns
匯入 Matplotlib:
import matplotlib.pyplot as plt
顯示圖表:
plt.show()
sns.relplot(x="x_variable_name",
y="y_variable_name",
data=pandas_df,
kind="scatter")
sns.catplot(x="x_variable_name",
y="y_variable_name",
data=pandas_df,
kind="bar")
設定 hue 會依子群著色,並在同一張圖上顯示。

在 relplot() 或 catplot() 設定 row 與/或 col,可將子群分到不同子圖呈現。

sns.set_style()sns.set_palette()sns.set_context()| Object Type | Plot Types | How to Add Title |
|---|---|---|
FacetGrid |
relplot(), catplot() |
g.figure.suptitle() |
AxesSubplot |
scatterplot(), countplot(), etc. |
g.set_title() |
新增 x、y 軸標籤:
g.set(xlabel="new x-axis label",
ylabel="new y-axis label")
旋轉 x 刻度標籤:
plt.xticks(rotation=90)
Seaborn 資料視覺化入門