Visualization with Matplotlib and Seaborn

Plotting distributions, relationships and model diagnostics so you see problems in data and models before metrics hide them.

Beginner · about 6 hours · difficulty 2/5

Learn first: pandas for Tabular Data

Plots are how you catch skewed features, outliers, label noise and overfitting curves. Matplotlib is the low-level engine; Seaborn sits on top and makes statistical plots from DataFrames in one line.

What to learn

  • Matplotlib object API: fig, ax = plt.subplots() and calling methods on ax. It scales to multi-panel figures far better than the plt. state machine.
  • Distributions: histograms, KDEs, box and violin plots (sns.histplot, sns.boxplot).
  • Relationships: scatter plots, pair plots, correlation heatmaps.
  • Categorical comparisons: bar and count plots with confidence intervals.
  • ML diagnostics: learning curves, confusion matrices, residual plots, ROC curves.

Habits

Always label axes and units, use log scales for heavy-tailed data, and prefer small multiples over cramming ten series on one chart. Interactive tools like Plotly are handy for dashboards but optional here.

Good enough to move on when you can produce a one-page EDA figure (distribution, relationship and category panels) for any new dataset in a few minutes.

Key concepts

  • Figure and Axes API
  • Distribution plots
  • Scatter and pair plots
  • Heatmaps
  • Diagnostic plots for models
  • Plotly for interactivity

Mini project

Build a 2x3 subplot EDA figure for the Palmer Penguins dataset: species counts, bill length distributions per species, a flipper versus body mass scatter, and a correlation heatmap.

Check yourself

When would a histogram mislead you where a box plot or ECDF would not?

Free resources