Matplotlib is the standard Python library for creating static visualizations. It was written starting in 2003 by John D. Hunter, a neurobiologist who wanted a MATLAB-like plotting library so he could analyze EEG data without leaving Python. It became the default plotting library for Python scientific computing and has remained so for two decades. There are newer alternatives — Plotly, Seaborn, Altair, Bokeh — but Matplotlib is the one you’ll see most often.
Matplotlib is structured as a core library with several submodules, the most important of which is Pyplot. Pyplot provides a high-level, MATLAB-style interface (plt.plot(x, y), plt.show()) that’s convenient for quick plots. The core library underneath gives more flexibility and finer control. Most real code uses both: Pyplot for the entry points, the core’s object model where extra control matters.
The conventional import:
import matplotlib.pyplot as pltTwo objects do most of the work:
- A Figure is the outer container — a sheet of paper. It owns all the visual elements: axes, title, legend, colors, layout.
- An Axes is a single plot region inside the Figure. Each Axes has its own x-axis and y-axis, its own coordinate system, its own labels, its own data.
The standard idiom that creates both at once:
fig, ax = plt.subplots()
ax.plot(x, y)
plt.show()For coordinates, Matplotlib supports several systems and a transform mechanism for converting between them. For layouts with multiple subplots, GridSpec handles complex arrangements. For tick marks, locators control where they appear. For coloring categorical or continuous data, colormaps map values to colors.
Matplotlib is the visualization layer underneath much of the data-science Python stack — Pandas’s .plot() methods use Matplotlib, Seaborn builds on top of it, scikit-learn’s metric-display helpers (ROC curve plots, Confusion matrix heat maps) render via Matplotlib. Learning Matplotlib pays off across nearly every visualization workflow.