Python / Data Science Essentials Interview Questions
What is Seaborn and how does it differ from Matplotlib?
Seaborn is a high-level statistical visualisation library built on top of Matplotlib. Where Matplotlib gives you full control over every pixel, Seaborn provides opinionated, attractive defaults and plot types designed specifically for statistical exploration — with far less boilerplate code.
| Aspect | Matplotlib | Seaborn |
|---|---|---|
| Level | Low-level — explicit control | High-level — declarative |
| Defaults | Functional but plain | Publication-quality themes out of the box |
| DataFrame integration | Manual (extract arrays) | Direct — pass df= and column names |
| Statistical plots | Manual calculation required | Built-in (regression, KDE, violin, pair) |
| Customisation | Unlimited | Matplotlib calls needed for fine-tuning |
import seaborn as sns import matplotlib.pyplot as plt # Load a built-in example dataset tips = sns.load_dataset('tips') # Seaborn: one line to create a scatter with regression line and hue sns.regplot(data=tips, x='total_bill', y='tip') # Matplotlib equivalent would require: # 1. Compute regression manually # 2. Plot scatter # 3. Plot fitted line # 4. Shade confidence interval â ~15 lines total # Themes and contexts sns.set_theme(style='whitegrid', context='notebook', palette='muted') # styles: darkgrid, whitegrid, dark, white, ticks # contexts: paper, notebook, talk, poster (scale font/line sizes)
Seaborn plots return Matplotlib Axes objects, so all standard Matplotlib customisation still applies after the Seaborn call: ax = sns.scatterplot(...); ax.set_title('My Title'). Seaborn does not replace Matplotlib — it is a complement that handles the tedious parts of statistical plotting.
More Related questions...