Matplotlib
Comprehensive plotting library for Python that creates publication-quality static and interactive figures.
Official Documentation ↗Matplotlib 3.8+ / Python 3.9+. Check the official docs for the latest API surface.Installation
pip install matplotlibMethods
No methods match this filter.
Overview
Matplotlib draws static, animated and interactive charts from Python data. It offers a quick pyplot interface and a fine-grained object API for controlling every element.
Core Methods
subplots creates a figure and axes, methods such as plot, scatter and hist draw data, and set and legend configure labels and legends. savefig writes the rendered result to a file.
Usage Notes
Use the object API in reusable code, pick the Agg backend on servers, and set layout options so labels are not clipped. Choose dpi and size deliberately for the target medium.
Common Pitfalls
Relying on the implicit pyplot state causes figures to leak between calls. Default fonts may lack glyphs for non-Latin text. Forgetting a non-interactive backend hangs in headless environments.
API reference evidence
Fetched from official sources on 2026-11-08T17:47:47+08:00 via WebFetch https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplots.html.
matplotlib.pyplot.subplots→ signature from https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplots.html; official text: “matplotlib.pyplot.subplots(nrows=1, ncols=1, *, sharex=False, sharey=False, squeeze=True, width_ratios=None, height_ratios=None, subplot_kw=None, gridspec_kw=None, **fig_kw)”Axes.plot→ signature from https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.plot.html; official text: “Axes.plot(*args, scalex=True, scaley=True, data=None, **kwargs)”Figure.savefig→ signature from https://matplotlib.org/stable/api/_as_gen/matplotlib.figure.Figure.savefig.html; official text: “savefig(fname, *, transparent=None, dpi=‘figure’, format=None, metadata=None, bbox_inches=None, pad_inches=0.1, facecolor=‘auto’, edgecolor=‘auto’, backend=None, **kwargs )”
FAQ
- What is the difference between pyplot and the object API?
- pyplot manages a global current figure for quick scripts, while the figure and axes object API gives explicit control and is safer inside functions and libraries.
- How do I set a headless backend?
- Set matplotlib.use("Agg") before importing pyplot so figures render without a display, which is required on servers and CI.
- Why do labels overlap or get cut off?
- Layout is not automatic for every element. Use constrained_layout or tight_layout and bbox_inches="tight" on save to fit labels and titles inside the output.
Report a problem with this API docOpens a pre-filled issue on GitHub.