散布図のカスタマイズ

Seaborn を使ったデータ可視化入門

Content Team

DataCamp

散布図の概要

2つの量的変数の関係を示す

これまでに見てきた内容:

  • サブプロット(colとrow)
  • 色によるサブグループ分け(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()

Scatter plot with varying point size

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()

Scatter plot with varying point size and color

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()

Scatter plot with varying color and style

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()

Scatter plot with more transparent points

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
Seaborn を使ったデータ可視化入門

練習しましょう!

Seaborn を使ったデータ可視化入門

Preparing Video For Download...