Customizing scatter plots

Introduction to Data Visualization with Seaborn

Erin Case

Data Scientist

Scatter plot overview

Show relationship between two quantitative variables

We've seen:

  • Subplots (col and row)
  • Subgroups with color (hue)

New Customizations:

  • Subgroups with point size and style
  • Changing point transparency

Use with both scatterplot() and relplot()

Introduction to Data Visualization with Seaborn

Subgroups with point size

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/
Introduction to Data Visualization with Seaborn

Point size and 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/
Introduction to Data Visualization with Seaborn

Subgroups with point style

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/
Introduction to Data Visualization with Seaborn

Changing point transparency

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/
Introduction to Data Visualization with Seaborn

Let's practice!

Introduction to Data Visualization with Seaborn

Preparing Video For Download...