Python Data Visualization, SQL Connectivity & EDA
Back to HIGH-IMPACT VISUAL STORYTELLING: MATPLOTLIB & SEABORN

Matplotlib Subplots & The Object-Oriented Interface

Master the Object-Oriented Matplotlib interface: fig, ax = plt.subplots(), multi-panel dashboards, and shared axes.

21 minutesVideo LessonPDF notes
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.
Loading progress...

Key moments

  1. Stateful vs OO Architecture — The instructor explains the architectural transition from stateful pyplot methods to explicit Figure and Axes objects.
  2. Instantiating Subplots — The video demonstrates initializing a default canvas and axes container using plt.subplots().
  3. OO Setter Methods — The lesson converts top-level pyplot formatting functions into explicit Axes methods like set_title and set_xlabel.
  4. Multi-Panel Grids — The instructor builds a two-row stacked dashboard by passing row and column dimensions to plt.subplots() and unpacking the axes.
  5. Synchronizing Shared Axes — The video applies sharex=True to align x-axis coordinate ranges across subplots and remove duplicate tick labels.
  6. Multi-Figure Workflows — The instructor splits panels into distinct, isolated Figure instances to manage multiple standalone visual assets in memory.
  7. Saving Independent Figures — The lesson concludes by exporting individual figure objects directly to image files using fig.savefig().
PDF notes

Frequently asked questions

What is the primary difference between a Figure and an Axes?

A Figure is the top-level container or canvas, whereas an Axes is an individual plot with coordinate systems, ticks, and chart elements contained inside that Figure.

How do I unpack subplots when creating a 2x2 grid?

Use nested tuple unpacking `fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)` or keep the array handle `fig, axs = plt.subplots(2, 2)` and index it via `axs[row, col]`.

Why did my top subplot's x-axis numbers vanish after setting sharex=True?

Matplotlib suppresses redundant interior tick labels when axes are shared to clean up visual clutter while keeping the coordinate scales synchronized.

How was this lesson?

Your feedback helps us refine explanations and catch bugs.