Introduction to Seaborn

Intermediate Data Visualization with Seaborn

Chris Moffitt

Instructor

Python Visualization Landscape

  • The python visualization landscape is complex and can be overwhelming

Python Visualization Landscape

Intermediate Data Visualization with Seaborn

Matplotlib

  • matplotlib provides the raw building blocks for Seaborn's visualizations
  • It can also be used on its own to plot data
import matplotlib.pyplot as plt
import pandas as pd

df = pd.read_csv("wines.csv")
fig, ax = plt.subplots() ax.hist(df['alcohol'])

Matplotlib histogram example

Intermediate Data Visualization with Seaborn

Pandas

  • pandas is a foundational library for analyzing data
  • It also supports basic plotting capability
import pandas as pd

df = pd.read_csv("wines.csv") df['alcohol'].plot.hist()

Pandas histogram example

Intermediate Data Visualization with Seaborn

Seaborn

  • Seaborn supports complex visualizations of data
  • It is built on matplotlib and works best with pandas' dataframes
Intermediate Data Visualization with Seaborn

Seaborn histplot

  • The histplot is similar to the histogram shown in previous examples
  • By default, generates a histogram but can also generate other complex plots
import seaborn as sns

sns.histplot(df['alcohol'])

Seaborn histplot example

Intermediate Data Visualization with Seaborn

Seaborn displot

  • The displot leverages the histplot and other functions for distribution plots
  • By default, it generates a histogram but can also generate other plot types
import seaborn as sns

sns.displot(df['alcohol'], kind='kde')

Seaborn displot example

Intermediate Data Visualization with Seaborn

pandas Histogram vs. Displot

  • Pandas histogram
    df['alcohol'].plot.hist()
    
    Pandas histogram example
    • Actual frequency of observations
    • No outline of bars
    • Wide bins
    • No x-axis label
  • Seaborn displot
    sns.displot(df['alcohol'])
    
    Seaborn displot example
    • Automatic label on x-axis
    • Muted color palette
    • Cleaner plot
Intermediate Data Visualization with Seaborn

Let's practice!

Intermediate Data Visualization with Seaborn

Preparing Video For Download...