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.
flowchart LR A["Your DataFrame"] --> B["seaborn.barplot / histplot / etc."] B --> C["Aggregation + styling
(handled automatically)"] C --> D["Matplotlib Figure/Axes
(rendered under the hood)"]
Install and import
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
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
Seaborn is built on top of which library?
Seaborn builds on Matplotlib, which is why you still call plt.title and plt.show on Seaborn plots.
Show answer
B — Matplotlib — Seaborn builds on Matplotlib, which is why you still call plt.title and plt.show on Seaborn plots.
What data shape do most Seaborn functions work best with?
Tidy data has one row per observation and one column per variable. That is why melt and pivot_table are useful in Pandas.
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.
In seaborn calls like sns.barplot(data=df, x="day", y="total_bill"), what do x and y receive?
The data argument is usually a DataFrame and the other arguments are column names.
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.
When there are multiple rows per category, what does Seaborn do that Matplotlib would not do for you?
Seaborn aggregates for you and draws a confidence interval, which you would otherwise compute by hand.
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
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.Exercise 2 – A First Line Plot
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.Exercise 3 – Tidy Data Shape
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.