Skip to content

Introduction to Matplotlib

Matplotlib is the core plotting library in Python.

  • Flexible and powerful
  • Works everywhere (scripts, notebooks)
  • Backbone for many libraries (including Seaborn)

Matplotlib was started by John Hunter in 2002 to bring a MATLAB-like plotting interface to Python. It can export charts to almost every common format — PNG, SVG, PDF, and more — which is why it’s still the default choice for publication-quality figures, even with newer libraries around.

diagram From data to a rendered chart mermaid
Matplotlib always builds a chart the same way: a Figure holds Axes, and you draw Artists onto the Axes.
pyplot quick
import matplotlib.pyplot as plt
 
plt.plot([1, 2, 3], [3, 2, 5])
plt.title("Quick plot")
plt.show()
OO API
import matplotlib.pyplot as plt
 
fig, ax = plt.subplots(figsize=(7, 4))
ax.plot([1, 2, 3], [3, 2, 5])
ax.set_title("OO plot")
ax.set_xlabel("x")
ax.set_ylabel("y")
plt.show()
  • Figure: the whole canvas
  • Axes: the plotting area
  • Artist: everything drawn on the figure

In this phase, we’ll focus on practical charts you need for analytics.

Continue to Anatomy of a Plot to see exactly how Figure, Axes, ticks, and labels fit together.

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading