Python Central HubSign in

Data Analytics with Python / Phase 6: Statistical Visualization with Seaborn

Introduction to Seaborn

Learn what Seaborn is, why it’s popular for statistical visualization, and how it fits on top of Matplotlib.

What is Seaborn?

Seaborn is a Python visualization library built on top of Matplotlib.

It provides:

  • Better default styles
  • High-level charts for statistics
  • Easy integration with Pandas DataFrames

Seaborn is especially useful in EDA because you can quickly create informative plots with fewer lines of code.

diagram Where Seaborn sits mermaid
Seaborn is a high-level layer over Matplotlib that understands DataFrames and statistics.

Install and import

Python
import seaborn as sns
import matplotlib.pyplot as plt
 
print(sns.__version__)

Seaborn’s core idea

Most Seaborn functions work well with tidy (long) data:

  • One row per observation
  • One column per variable

That’s why Pandas reshaping (melt, pivot_table) is useful.

A first Seaborn plot

Python
import seaborn as sns
import matplotlib.pyplot as plt
 
x = [1, 2, 3, 4, 5]
y = [1, 4, 9, 16, 25]
 
sns.lineplot(x=x, y=y)
plt.title("Seaborn line plot")
plt.tight_layout()
plt.show()

Why analysts like Seaborn

  • Built-in confidence intervals and aggregations in some plots
  • Simple API for categorical comparisons
  • Great for quickly exploring distributions and relationships

Check your understanding

quizCheck yourself
  1. Seaborn is built on top of which library?

    Show answer

    B — Matplotlib — Seaborn builds on Matplotlib, which is why you still call plt.title and plt.show on Seaborn plots.

  2. What data shape do most Seaborn functions work best with?

    Show answer

    A — Tidy (long) data with one row per observation — Tidy data has one row per observation and one column per variable. That is why melt and pivot_table are useful in Pandas.

  3. In seaborn calls like sns.barplot(data=df, x="day", y="total_bill"), what do x and y receive?

    Show answer

    B — Column names from the DataFrame passed as data — The data argument is usually a DataFrame and the other arguments are column names.

  4. When there are multiple rows per category, what does Seaborn do that Matplotlib would not do for you?

    Show answer

    D — Averages them and draws a confidence interval — Seaborn aggregates for you and draws a confidence interval, which you would otherwise compute by hand.

Next

Continue to Seaborn vs Matplotlib to see exactly when to reach for each library — and how they work together in the same script.

🧪 Try It Yourself

Exercise 1 – Import and Check the Version

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 2 – A First Line Plot

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 3 – Tidy Data Shape

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Was this page helpful?

Let us know how we did