關係圖與子圖入門

Seaborn 資料視覺化入門

Content Team

DataCamp

連續變數的提問

關係圖

  • 身高 vs. 體重

身高對體重的散佈圖

Seaborn 資料視覺化入門

連續變數的提問

關係圖

  • 身高 vs. 體重
  • 缺課次數 vs. 期末成績

缺課次數對期末成績的散佈圖

Seaborn 資料視覺化入門

連續變數的提問

關係圖

  • 身高 vs. 體重
  • 缺課次數 vs. 期末成績
  • GDP vs. 識字率(%)

GDP 對識字率百分比的散佈圖

Seaborn 資料視覺化入門

含色相分類的散佈圖

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
Seaborn 資料視覺化入門

含子圖的散佈圖

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
Seaborn 資料視覺化入門

認識 relplot()

  • 建立「關係圖」:散佈圖或折線圖

為什麼用 relplot() 而不是 scatterplot()

  • relplot() 可在單一圖中建立多個子圖
Seaborn 資料視覺化入門

scatterplot() vs. relplot()

使用 scatterplot()

import seaborn as sns
import matplotlib.pyplot as plt

sns.scatterplot(x="total_bill", 
                y="tip", 
                data=tips)

plt.show()

使用 relplot()

import seaborn as sns
import matplotlib.pyplot as plt

sns.relplot(x="total_bill", 
            y="tip", 
            data=tips,
            kind="scatter")

plt.show()
1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
Seaborn 資料視覺化入門

欄方向子圖

import seaborn as sns
import matplotlib.pyplot as plt

sns.relplot(x="total_bill", 
            y="tip", 
            data=tips,
            kind="scatter",
            col="smoker")

plt.show()

以欄呈現吸菸與否子圖的散佈圖

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
Seaborn 資料視覺化入門

列方向子圖

import seaborn as sns
import matplotlib.pyplot as plt

sns.relplot(x="total_bill", 
            y="tip", 
            data=tips,
            kind="scatter",
            row="smoker")

plt.show()

以列呈現吸菸與否子圖的散佈圖

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
Seaborn 資料視覺化入門

列與欄的子圖

import seaborn as sns
import matplotlib.pyplot as plt

sns.relplot(x="total_bill", 
            y="tip", 
            data=tips,
            kind="scatter",
            col="smoker",
            row="time")

plt.show()

吸菸與時段的子圖散佈圖

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
Seaborn 資料視覺化入門

以星期分組的次族群

以欄呈現星期子圖的散佈圖

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
Seaborn 資料視覺化入門

欄換行(col_wrap)

import seaborn as sns
import matplotlib.pyplot as plt

sns.relplot(x="total_bill", 
            y="tip", 
            data=tips,
            kind="scatter",
            col="day",
            col_wrap=2)

plt.show()

以欄分組並換行為兩列的星期子圖散佈圖

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
Seaborn 資料視覺化入門

欄位排序(col_order)

import seaborn as sns
import matplotlib.pyplot as plt

sns.relplot(x="total_bill", 
            y="tip", 
            data=tips,
            kind="scatter",
            col="day",
            col_wrap=2,
            col_order=["Thur",
                       "Fri",
                       "Sat",
                       "Sun"])

plt.show()

依指定順序排列星期子圖的散佈圖

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
Seaborn 資料視覺化入門

一起來練習吧!

Seaborn 資料視覺化入門

Preparing Video For Download...