Matplotlib vs Seaborn (simple comparison)
Matplotlib
- Low-level building blocks
- Maximum control
- More code required for common charts
Seaborn
- High-level statistical plots
- Beautiful defaults
- Works naturally with DataFrames
In practice, you often use both together:
- Seaborn creates the plot
- Matplotlib is used to customize labels, titles, and layout
flowchart LR A["DataFrame"] --> B["sns.barplot / boxplot / etc.
(the statistical chart)"] B --> C["plt.title / xlabel / ylabel
(Matplotlib finishing touches)"] C --> D["plt.tight_layout(); plt.show()"]
Example: same idea, different style
Matplotlib
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [10, 6, 8, 4]
plt.plot(x, y, marker="o")
plt.title("Matplotlib line")
plt.xlabel("x")
plt.ylabel("y")
plt.tight_layout()
plt.show()Seaborn
import seaborn as sns
import matplotlib.pyplot as plt
sns.set_theme(style="whitegrid")
x = [1, 2, 3, 4]
y = [10, 6, 8, 4]
sns.lineplot(x=x, y=y, marker="o")
plt.title("Seaborn line")
plt.xlabel("x")
plt.ylabel("y")
plt.tight_layout()
plt.show()Rule of thumb
- Use Seaborn for quick exploration (EDA)
- Use Matplotlib for fine-grained control or custom layouts
Good habit
Even when using Seaborn, always add:
- Title
- Axis labels
- Reasonable figure size
- Tight layout
Check your understanding
Which statement best matches the lesson rule of thumb?
Seaborn creates the plot fast, and Matplotlib customizes labels, titles and layout.
Show answer
A — Seaborn for quick exploration, Matplotlib for fine-grained control — Seaborn creates the plot fast, and Matplotlib customizes labels, titles and layout.
Which call applies a white background with grid lines in the lesson example?
sns.set_theme(style="whitegrid") changes the look of subsequent plots.
Show answer
B — sns.set_theme(style="whitegrid") — sns.set_theme(style="whitegrid") changes the look of subsequent plots.
What habits does the lesson say to keep even when using Seaborn?
Title, axis labels, a sensible figure size and tight_layout keep plots readable.
Show answer
B — Title, axis labels, reasonable figure size and tight layout — Title, axis labels, a sensible figure size and tight_layout keep plots readable.
Which is a typical Seaborn advantage listed in the lesson?
Seaborn offers high-level statistical plots with good defaults, while Matplotlib offers low-level building blocks.
Show answer
D — Beautiful defaults and natural DataFrame support — Seaborn offers high-level statistical plots with good defaults, while Matplotlib offers low-level building blocks.
Next
Continue to Distribution Plots (displot, histplot) to start exploring how a single numeric variable is spread out.
🧪 Try It Yourself
Exercise 1 – Switch the Seaborn Theme
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 – Same Data, Two Libraries
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 – Pick the Right Tool
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.