Python Central HubSign in

Data Analytics with Python / Phase 5: Data Visualization with Matplotlib

Introduction to Matplotlib

Learn what Matplotlib is, why it’s foundational in Python visualization, and how plotting works.

What is 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.

How a plot gets built

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.

Two common ways to plot

1) Pyplot (quick)

Python
import matplotlib.pyplot as plt
 
plt.plot([1, 2, 3], [3, 2, 5])
plt.title("Quick plot")
plt.show()
Python
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()

Key terms

  • 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.

Check your understanding

quizCheck yourself
  1. Which approach does the lesson recommend for building plots?

    Show answer

    A — The object-oriented API with fig, ax = plt.subplots() — Pyplot is quick, but the object-oriented API is recommended because it is more consistent and reusable.

  2. In Matplotlib terms, what is an Axes?

    Show answer

    A — The plotting area — The Figure is the whole canvas, the Axes is the plotting area, and an Artist is everything drawn on the figure.

  3. Which statement about Matplotlib is true?

    Show answer

    A — It can export PNG, SVG, PDF and more, and it is the backbone for libraries such as Seaborn — Matplotlib started in 2002 and exports to almost every common format, which is why it suits publication-quality figures.

  4. Which call actually displays the figure in a script?

    Show answer

    A — plt.show() — The examples end with plt.show(), which renders the chart you built.

Next

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

🧪 Try It Yourself

Exercise 1 – Object-oriented basics

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 2 – Labelling an Axes

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 3 – A grid of Axes

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Was this page helpful?

Let us know how we did