Basic principles and structures

Matplotlib Basics

3 min read

Published Oct 5 2025, updated Aug 17 2026


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 pltplt.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 Figurefrom matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas# 1. Create a blank Figurefig = Figure()   # 2. Attach a rendering backendcanvas = FigureCanvas(fig)    # 3. Add an Axesax = fig.add_subplot(111)# 4. Add Artists to the Axesax.plot([1,2,3], [4,5,6])# 5. Save the Figure to a filefig.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.

© 2025 SimpleSteps.guide
AboutFAQPoliciesContact
Matplotlib Basics | Basic principles and structures | SimpleSteps.guide