Basic principles and structures

Matplotlib Basics

3 min read

Published Oct 5 2025


15
0
0
0

ChartsGraphsMatplotlibNumPyPandasPythonVisualisation

The Basic Structure of a Matplotlib Chart

At its core, Matplotlib’s architecture is object-oriented.
Every plot is made of nested objects that together describe what to draw and how to draw it.


Figure - main canvas

  • A Figure is the entire plotting window or page.
  • It’s the top-level container — think of it as the paper or canvas.
  • You can have multiple figures open at once, and each can contain one or more plots.
  • If you have multiple figures open and then show them, each figure is displayed in its own window, where as if you add multiple plots on a single figure they will all be displayed in the same window.
  • There are properties that you can set for overall figure (canvas) title, background colours, size of the canvas etc.

Axes — the actual plot area

  • An Axes is a single plot or chart inside the figure.
  • It defines:
    • The data coordinate system
    • The x- and y-axis lines
    • The labels, titles, ticks, etc.
  • Each Figure can have one or more Axes (e.g., subplots).


Axis — The Number Line(s) of the Axes

  • Inside each Axes, there are Axis objects:
    • xaxis → controls the x scale, ticks, labels
    • yaxis → controls the y scale, ticks, labels


Artist — Anything That Gets Drawn

  • Every visible element in a plot is an Artist.
    • Lines (Line2D)
    • Text labels (Text)
    • Shapes (Patch)
    • Images, Legends, Titles, Ticks, etc.
  • Even the Figure and Axes themselves are actually Artists


Matplotlib Object Hierarchy:

  • Figure - (overall canvas)
    • Axes - (individual plot area or chart)
      • Axis - (x and y coordinate systems)
      • Artists (everything drawn: lines, text, shapes, etc.)





Automatic vs Manual Creation

Matplotlib can build all the structure for you, or you can manually construct it step-by-step.


Automatic

import matplotlib.pyplot as plt
plt.plot([1,2,3], [4,5,6])
plt.show()


Matplotlib automatically:

  1. Creates a Figure
  2. Creates an Axes
  3. Adds a Line2D Artist
  4. Draws it

Manual (more granular control)

You can create and manage everything yourself:

from matplotlib.figure import Figure
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas

# 1. Create a blank Figure
fig = Figure()

# 2. Attach a rendering backend
canvas = FigureCanvas(fig)

# 3. Add an Axes
ax = fig.add_subplot(111)

# 4. Add Artists to the Axes
ax.plot([1,2,3], [4,5,6])

# 5. Save the Figure to a file
fig.savefig("test_matplotlib_output.png")





plt.show()

This function will display all open figures. If there are more than 1 figure open, then it will display each of them in separate windows.

To essentially, once you have created your charts, calling this method will display it on the screen.

By default, code execution will pause when the chart windows open, and resume once all figure windows are closed. You can change this behaviour by passing the block=False parameter to the show method.


Products from our shop

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Mug

Docker Cheat Sheet Mug

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Mug

Vim Cheat Sheet Mug

SimpleSteps.guide branded Travel Mug

SimpleSteps.guide branded Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - Black

Developer Excuse Javascript Mug - Black

SimpleSteps.guide branded stainless steel water bottle

SimpleSteps.guide branded stainless steel water bottle

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Dark

Developer Excuse Javascript Hoodie - Dark

© 2025 SimpleSteps.guide
AboutFAQPoliciesContact