Pythonmatplotlibv3.9.2
PythonIntermediate

matplotlib

The go-to plotting library for Python — create static, animated, and interactive visualizations with a MATLAB-like API.

visualizationplottingdata-sciencechartsgraphs
The Problem

You have data — arrays, dataframes, model outputs — and you need to see it. Whether it's a quick line chart to check a trend or a publication-quality figure with subplots, you need a library that can do both without switching tools.

Mental Model

Think of matplotlib as a canvas + paintbrush system. The Figure is the canvas, Axes are individual plot areas, and everything (lines, labels, ticks, colors) is an Artist you can configure. The pyplot interface is a shortcut for common operations, but the object-oriented API gives you full control.

60-second start

Plot a line chart

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 10, 100)
y = np.sin(x)
fig, ax = plt.subplots(figsize=(8, 4))
ax.plot(x, y, color='steelblue', linewidth=2, label='sin(x)')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_title('Sine Wave')
ax.legend()
ax.grid(alpha=0.3)
plt.tight_layout()
plt.show()

Use it when

Scientific plots, publication figures, embedding charts in reports, quick data exploration, custom visualizations that seaborn can't express, or when you need pixel-level control over a chart.

Skip it when

Interactive web dashboards (use Plotly or Bokeh), real-time streaming charts, or when you just want something beautiful fast (try seaborn first).

Alternatives
seabornHigher-level statistical plots with better defaults, built on top of matplotlib
plotlyInteractive web-first charts, great for dashboards
altairDeclarative grammar-of-graphics approach, clean API

Ready to explore the full API?

See every class, function, and relationship in an interactive graph.