Further Reading: Subplots and GridSpec
Tier 1: Essential Reading
The matplotlib Subplots Tutorial. matplotlib.org/stable/tutorials/intermediate/arranging_axes.html
The official matplotlib tutorial on arranging multiple Axes in a figure. Covers plt.subplots, GridSpec, subplot_mosaic, subfigures, and the layout managers (constrained_layout, tight_layout). Essential reading and the most up-to-date source for the specific API calls. The tutorial is updated with each matplotlib release.
The matplotlib GridSpec Tutorial. matplotlib.org/stable/tutorials/intermediate/gridspec.html
A focused tutorial on GridSpec specifically, with examples of width_ratios, height_ratios, and slicing notation. Good for understanding how GridSpec works before you use it in your own code.
VanderPlas, Jake. Python Data Science Handbook. 2nd ed. O'Reilly Media, 2023.
Already recommended in previous chapters. The section "Multiple Subplots" in Chapter 4 covers plt.subplots, plt.subplot, GridSpec, and related tools with clear examples. Free online at jakevdp.github.io/PythonDataScienceHandbook/.
Tier 2: Recommended Specialized Sources
The Python Graph Gallery — Multi-Panel Section. python-graph-gallery.com/subplots/ A visual gallery of multi-panel matplotlib figures with full source code. Browse to find examples close to what you want, copy the code, and modify. Faster than reading the API documentation for specific layout needs.
Rougier, Nicolas P. Scientific Visualization: Python + Matplotlib. Self-published, 2021. Already recommended, Rougier's book has a chapter on complex figure composition that covers GridSpec, subfigures, and advanced layout techniques. Freely available at github.com/rougier/scientific-visualization-book.
Hunter, John D., and Michael Droettboom. "Matplotlib." In The Architecture of Open Source Applications, Volume II, 2012. The matplotlib architects' description of the library, including how the layout engine works internally. Useful for understanding why constrained_layout is better than tight_layout and what matplotlib is actually doing when it arranges subplots.
Tufte, Edward R. Envisioning Information. Graphics Press, 1990. Already recommended for Chapter 8, Tufte's book is the conceptual foundation for small multiples — the design principle that multi-panel figures implement. Read alongside the matplotlib documentation to connect the design concepts to the code.
The matplotlib Gallery — Subplots Section. matplotlib.org/stable/gallery/subplots_axes_and_figures/ The official matplotlib gallery's dedicated section for subplot arrangements. Dozens of examples organized by layout type. Essential reference for specific layout problems.
Tier 3: Tools, References, and Examples
| Resource | URL / Source | Description |
|---|---|---|
| plt.subplot_mosaic documentation | matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplot_mosaic.html | The subplot_mosaic function (matplotlib 3.3+) accepts a string pattern (like "A;BC" or "AABB;CCDD") and creates a layout from it. An alternative to GridSpec for some layouts, and often easier to read. |
| constrained_layout guide | matplotlib.org/stable/tutorials/intermediate/constrainedlayout_guide.html | Deep dive on constrained_layout: how it works, when to use it, and what it cannot handle. |
| subfigures tutorial | matplotlib.org/stable/gallery/subplots_axes_and_figures/subfigures.html | Examples of fig.subfigures() for composing figures from logical groups. |
| Inset axes examples | matplotlib.org/stable/gallery/subplots_axes_and_figures/zoom_inset_axes.html | Specific examples of inset axes and zoom panels. |
| seaborn FacetGrid | seaborn.pydata.org/tutorial/axis_grids.html | seaborn's high-level wrapper around matplotlib subplots for faceted (small-multiple) displays. Often simpler than raw matplotlib for common small-multiple needs. |
| Scientific figure templates | github.com/rougier/matplotlib-figures | A repository of matplotlib examples specifically for scientific publication figures, with GridSpec-based multi-panel layouts. |
| The Pudding visual essays | pudding.cool | Not a matplotlib reference, but an excellent source of complex multi-panel layouts to study and mentally decompose. |
A note on reading order: If you want one additional source, read the official matplotlib subplots tutorial. It is the single most useful reference for this chapter's material. For design inspiration, browse the Python Graph Gallery and the NYT Upshot section. For complex scientific figures, read Rougier's book.