Putting it all together

Introduction to Data Visualization with Seaborn

Erin Case

Data Scientist

Getting started

To import Seaborn:

import seaborn as sns

To import Matplotlib:

import matplotlib.pyplot as plt

To show a plot:

plt.show()
Introduction to Data Visualization with Seaborn

Relational plots

  • Show the relationship between two quantitative variables
  • Examples: scatter plots, line plots
sns.relplot(x="x_variable_name", 
            y="y_variable_name", 
            data=pandas_df, 
            kind="scatter")
Introduction to Data Visualization with Seaborn

Categorical plots

  • Show the distribution of a quantitative variable within categories defined by a categorical variable
  • Examples: bar plots, count plots, box plots, point plots
sns.catplot(x="x_variable_name", 
            y="y_variable_name", 
            data=pandas_df, 
            kind="bar")
Introduction to Data Visualization with Seaborn

Adding a third variable (hue)

Setting hue will create subgroups that are displayed as different colors on a single plot.

Scatter plot with hue

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
Introduction to Data Visualization with Seaborn

Adding a third variable (row/col)

Setting row and/or col in relplot() or catplot() will create subgroups that are displayed on separate subplots.

Scatter plot with subplots

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
Introduction to Data Visualization with Seaborn

Customization

  • Change the background: sns.set_style()
  • Change the main element colors: sns.set_palette()
  • Change the scale: sns.set_context()
Introduction to Data Visualization with Seaborn

Adding a title

Object Type Plot Types How to Add Title
FacetGrid relplot(), catplot() g.fig.suptitle()
AxesSubplot scatterplot(), countplot(), etc. g.set_title()
Introduction to Data Visualization with Seaborn

Final touches

Add x- and y-axis labels:

g.set(xlabel="new x-axis label",
      ylabel="new y-axis label")

Rotate x-tick labels:

plt.xticks(rotation=90)
Introduction to Data Visualization with Seaborn

Let's practice!

Introduction to Data Visualization with Seaborn

Preparing Video For Download...