MatplotlibXBy @CodeWithMunnaX
Catalog
Track: Subplots & Layouts
Layouts12 mins

24. Inset Axes & Mini Zoom Plots

When presenting signals with fine detail (such as high-frequency pulses or sudden price spikes), an inset magnification axes inside the main plot lets viewers inspect both the macro context and micro detail.

Mental Model Intuition

A magnifying glass held over a tiny detail in a large oil painting.

Core Concepts & Mechanics

`fig.add_axes([left, bottom, width, height])`Placement

Coordinates are specified in normalized figure fractions from 0.0 (bottom-left) to 1.0 (top-right).

`[0.6, 0.6, 0.25, 0.25]` places a 25% sized square box near the top-right corner.
ax_inset = fig.add_axes([0.6, 0.6, 0.25, 0.25])

Common Beginner Mistakes & Pro Fixes

Avoid the top errors and bad plotting practices that trip up new Python developers

Troubleshooting

Quick Lesson Takeaways

  • `fig.add_axes([left, bottom, width, height])` places an axes anywhere on canvas.
  • Coordinates are normalized fractions of the figure (0.0 to 1.0).
  • Perfect for zoom insets, thumbnails, and colorbars.
Topic 24 • Python IDE
Python 3.12 • Matplotlib
Run Python code to inspect terminal output.

Real-World Datasets (1-Click Switcher)

Switch from abstract numbers to relatable Cricket, Cinema & Business charts

5 Curated Datasets

Hands-on Challenge: Add an Inset Axes

+50 XP

Write Matplotlib code to solve the objective and see your live plot render

Objective Instructions:

Create a figure, plot `[1, 2, 3]` on main axes, and add an inset axes using `fig.add_axes([0.6, 0.6, 0.25, 0.25])` with title 'Zoom'.

Required Keywords:✓ add_axes✓ set_title
Challenge Code Editor
Challenge Output GraphLive Vector Preview
Write code on the left to render live challenge plot
End of Lesson Knowledge Check

Quick Mini Quiz: 2 Concept Questions

Test your understanding to unlock the lesson completion badge

Q1

Which Matplotlib function is used to create a standard continuous 2D line plot?

Q2

What must you call after specifying label='...' so that the legend actually appears on the canvas?

0 of 2 answered