Comprehensive toolkit for Matplotlib 3.10.8, the Python plotting library for static, animated, and interactive visualizations. Use when generating plots (line, scatter, bar, histogram, contour, 3D), customizing figures/axes/colors/text, managing backends and output formats, configuring rcParams, building subplots/gridspecs, or integrating with Jupyter notebooks.
Comprehensive toolkit for Matplotlib 3.10.8, the Python plotting library for static, animated, and interactive visualizations. Use when generating plots (line, scatter, bar, histogram, contour, 3D), customizing figures/axes/colors/text, managing backends and output formats, configuring rcParams, building subplots/gridspecs, or integrating with Jupyter notebooks.
Matplotlib is the foundational Python plotting library for creating static, animated, and interactive visualizations. It produces publication-quality figures in a wide variety of formats and supports all major operating systems. Built on NumPy arrays, it provides both a high-level pyplot interface for quick scripting and a lower-level object-oriented API for fine-grained control.
Matplotlib 3.10.8 introduces support for constrained layout as the default, improved color handling with alpha tuples, enhanced animation writers (PillowWriter, FFMpegWriter), and refined subplot mosaic layouts. It works seamlessly with Jupyter notebooks, IPython, PyQt/PySide, Tkinter, wxPython, and headless environments.
When to Use
Generating 2D plots: line charts, scatter plots, bar charts, histograms, box plots, violin plots
Creating gridded data visualizations: heatmaps (imshow), contour plots, pcolormesh
Building statistical visualizations: ECDFs, hexbin, error bars, stackplots
Producing 3D plots: surfaces, wireframes, scatter3d, bar3d
Saving figures to PNG, SVG, PDF, PS, or PGF formats
Customizing plot appearance through rcParams, style sheets, and colormaps
Creating animations with FuncAnimation or ArtistAnimation
Embedding Matplotlib in GUI applications (Qt, Tk, wx) or web servers
Working with date/time data, custom tick locators/formatters
Building complex multi-axis layouts with subplot_mosaic or GridSpec
Core Concepts
The Object Hierarchy
Everything visible in a Matplotlib figure is an Artist. The hierarchy is:
Figure — the top-level container (window, canvas, or output file). Created via plt.figure() or plt.subplots().
Axes — a plotting area within a Figure. Each Axes has its own x/y axes (Axis objects), data region, title, labels, and legend. Most plotting methods live here.
Axis — the tick-generating objects that control scale, limits, locators, and formatters.
Artist — everything visible: Line2D, Text, Rectangle, Patch, Collection, Image, etc. Artists are drawn when the Figure is rendered.
Two API Styles
Object-oriented (OO) style — recommended for most use cases:
The OO style is preferred because it avoids global state, supports multiple figures/axes cleanly, and makes customization explicit.
Creating Figures and Axes
# Empty figure, no axes
fig = plt.figure()
# Figure with a single Axes
fig, ax = plt.subplots()
# 2x2 grid of Axes
fig, axs = plt.subplots(2, 2)
# Complex layout with subplot_mosaic
fig, axs = plt.subplot_mosaic([['left', 'top'], ['left', 'bottom']])
The layout='constrained' parameter (default in 3.10) automatically adjusts spacing to prevent label overlap. Use fig.subplots_adjust() for manual control or tight_layout() for the legacy approach.
Colors and Colormaps: Color specification formats (RGB, hex, named, xkcd, Tableau), colormaps (sequential, diverging, qualitative, cyclic), normalization, alpha blending, custom colorbars → Colors and Colormaps
Text, Annotations, and Math: Text placement, annotations with arrows, mathematical expressions (LaTeX-like syntax), font management, text properties, mathtext rendering → Text and Annotations
Customization and rcParams: Runtime rc settings, style sheets (built-in and custom), matplotlibrc configuration, rc_context for temporary changes, cycler for property cycles → Customization
Animations: FuncAnimation, ArtistAnimation, blitting for performance, saving to MP4/GIF via PillowWriter and FFMpegWriter → Animations
3D Plotting: mplot3d toolkit, 3D line/scatter/surface/wireframe plots, volumetric data (voxels), tri-surface, contour3D → 3D Plotting
API Reference Summary: pyplot module functions, Axes methods, Artist base class, Figure methods, Axis locators and formatters, patches, collections → API Reference