自訂散佈圖

Seaborn 資料視覺化入門

Content Team

DataCamp

散佈圖總覽

呈現兩個數值變數的關係

已學過:

  • 子圖(colrow
  • 以顏色區分子群(hue

新的自訂項目:

  • 以點大小與樣式區分子群
  • 調整點的透明度

可搭配 scatterplot()relplot() 使用

Seaborn 資料視覺化入門

以點大小區分子群

import seaborn as sns
import matplotlib.pyplot as plt

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

plt.show()

不同點大小的散佈圖

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

點大小與色彩(hue)

import seaborn as sns
import matplotlib.pyplot as plt

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

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", 
            hue="smoker", 
            style="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

# Set alpha to be between 0 and 1
sns.relplot(x="total_bill", 
            y="tip", 
            data=tips, 
            kind="scatter", 
            alpha=0.4)

plt.show()

較高透明度的散佈圖

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

一起來練習吧!

Seaborn 資料視覺化入門

Preparing Video For Download...