Visitar URL original
Object Hierarchy (Video) – Real Python
Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Object Hierarchy

One important, big-picture concept for matplotlib is its object hierarchy. If you’ve ever worked through an introductory matplotlib tutorial, you may have started with a little bit of code that looks like this:

Language: Python
plt.plot([1,2,3,4],[1,4,9,16])

This code plots a straight line. The problem is that this small amount of code hides the fact that a plot like this is really made up of a bunch of individual objects, and those objects contain their own objects. It’s a hierarchy of objects that all come together to make the beautiful graphics you’ll see in this course.

00:00 One important, big picture Matplotlib concept is its object hierarchy. If you’ve ever worked through a basic Matplotlib tutorial, you’ve probably started with a little bit of code that looks like this.

00:14 This code plots a straight line. The problem is, this little amount of code hides the fact that a plot like this is really made up of a bunch of individual objects, and those objects contain their own objects.

00:30 It’s a hierarchy of objects that all come together in order to make the beautiful looking graphics we’ll see in a little bit.

00:39 The outermost object in the Matplotlib graphic is called the Figure. This represents basically your entire window, which you can move around and resize.

00:51 Inside the Figure object are one or more Axes—spelled with an e, not to be confused with Axis, spelled with an i.

01:02 Axes can represent a single graphic, like a scatter plot or a histogram. Inside of that is one or more Axis, like the XAxis or YAxis, and probably a title as well as lots of little points.

01:20 You can dig even deeper and get each tick mark or label, which belongs to either the XAxis or YAxis object. We can say that the tick mark belongs to the Axis object, which belongs to the Axes, which belongs to the Figure.

01:38 This image here shows just how many objects make up a graphic in Matplotlib. Just remember: the XAxis or YAxis, collectively known as axes, belongs to an Axes object.

01:54 And now you understand why Matplotlib can be confusing.

Avatar image for alekscooper

alekscooper on June 7, 2026

0:13 “This code plots a straight line”, no it doesn’t, it plots what looks like a y=x^2 kind of thing :)

Avatar image for Bartosz Zaczyński

Bartosz Zaczyński RP Team on June 11, 2026

You’re right @alekscooper, good catch 🙂 That snippet plots [1, 2, 3, 4] against [1, 4, 9, 16], and since 1, 4, 9, 16 are the squares of 1, 2, 3, 4, the line curves upward and looks just like a piece of y = x². Calling it “a straight line” in the narration isn’t accurate.

Strictly speaking, plt.plot() joins the four points with straight segments rather than a smooth curve, but the rising slopes (3, then 5, then 7) give it that unmistakable quadratic bend.

It doesn’t change the point of the lesson, which is that even this tiny snippet is backed by a whole hierarchy of Figure, Axes, and Axis objects. But the wording is off, so I’ll flag it for the rest of the team to fix in the narration and transcript. Thanks for posting about it!

Become a Member to join the conversation.