Skip to main content

Seaborn (Part 1): Introduction to Seaborn

Seaborn sits on Matplotlib but speaks Statistics + DataFrames fluently. After mastering raw Matplotlib in Parts 1–3, Seaborn trims boilerplate while keeping plots honest.

Install:

pip install seaborn pandas

📚 Prerequisites

  • Comfortable with Pandas.
  • Exposure to matplotlib Figure/Axes terminology.

🎯 What you'll master

  • Use sns.set_theme() to establish consistent aesthetics.
  • Pair Seaborn plotting functions with tidy DataFrames.

Themes and palettes

import seaborn as sns

sns.set_theme(style="whitegrid", context="talk")

whitegrid helps compare magnitudes horizontally; lighten context (notebook, talk, poster) matching output medium.


Relational plotting preview

Even before specialized statistical charts, Seaborn excels at exploratory scatter/line combos:

import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd

df = pd.DataFrame(
{
"engineer": ["A", "A", "B", "B"],
"latency": [120, 150, 90, 95],
"build": ["v1", "v2", "v1", "v2"],
}
)

fig, ax = plt.subplots()
sns.scatterplot(data=df, x="build", y="latency", hue="engineer", ax=ax)
plt.show()

Returning Matplotlib axes

Every Seaborn function returns the Axes it drew on—you can tweak labels exactly as with Matplotlib.


💡 Key takeaways

  • Seaborn is not a silver bullet: if you distort bin widths or jitter without purpose, prettiness still masks truth.
  • Call sns.set_theme once near program entry—not inside hot loops—to avoid conflicting styles.

➡️ Next steps

Use Seaborn-specific statistical plots in Seaborn (Part 2): Histograms and box plots.