14

Can you please clarify some Matplotlib terminology:

  • is the word "subplots" (or "subplot"?) synonymous to "axes"?
  • what are singulars / plurals of "axes" and "axis"?
Aivar
  • 6,814
  • 5
  • 46
  • 78

3 Answers3

17

This is indeed a confusing matter.

In English language the singular is axis and the plural is axes. Two of the kind axis form two axes.

In matplotlib, a matplotlib.axes._axes.Axes object is often simply called "axes". This object incorporates an xaxis and a yaxis, thus the name. But speaking of that object, one would call it axes in singular. Several of those are still called axes.

Every subplot is an Axes object, but there are Axes objects, which are no AxesSubplot object. E.g. an axes, which is created through the subplot mechanism is a matplotlib.axes._subplots.AxesSubplot. This class derives from matplotlib.axes._axes.Axes, thus this subplot is an axes. You can however also create axes via different mechanisms, e.g. by adding an axes to the figure, fig.add_axes(). This would then not be a subplot, but an axes, matplotlib.axes._axes.Axes.

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

print(ax)         # Axes(0.125,0.11;0.775x0.77)
print(type(ax))   # <class 'matplotlib.axes._subplots.AxesSubplot'>

ax2 = fig.add_axes([0.8,0.1,0.05,0.8])

print(ax2)       # Axes(0.8,0.1;0.05x0.8)
print(type(ax2)) # <class 'matplotlib.axes._axes.Axes'>

There are also other axes, like e.g. inset axes, mpl_toolkits.axes_grid1.parasite_axes.AxesHostAxes. This object would also be called axes.

from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
axins = zoomed_inset_axes(ax, 0.2, loc=3) 

print(axins)       # Axes(0.125,0.11;0.775x0.77)     
print(type(axins)) # <class 'mpl_toolkits.axes_grid1.parasite_axes.AxesHostAxes'>
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
  • 1
    Could you explain a little bit more about the thoughts behind the name “axes”? According to the figure [here](https://stackoverflow.com/a/33263181), axes seems to stand something like a drawing area or a floating canvas rather than just the x and y axes. I’m wonder why this object is named “axes” if it really means a drawing area. Thanks! – xslittlegrass Oct 10 '17 at 05:44
  • @xslittlegrass The "axes" in matplotlib is really the `matplotlib.axes._axes.Axes` object, which incorporates the xaxis, yaxis, their labels, ticks etc. The canvas is everything; it can host one figure and a figure can host several axes. We don't speak about drawing area because you can draw everywhere, also outside of the axes. – ImportanceOfBeingErnest Oct 10 '17 at 09:24
  • 2
    @ImportanceOfBeingErnest, its a great answer. However do you think the emphasized line could be better understood if written as **Every `subplot` object is an `axes` object, but there are `axes` objects, which are not `subplot` objects**. – Gaurav Singhal May 23 '18 at 16:42
  • What's the difference between `Axes` and `AxesSubplot`? If subplot is an instance of `AxesSubplot`. What does an instance `Axes` represent? – Iresh Dissanayaka Jun 07 '21 at 19:37
4

Axes is the plural of axis. A subplot usually has an x-axis and a y-axis, which together form the two axes of the subplot.

Let's talk in terms of function/class names:

Figure.add_subplot or pyplot.subplot return a AxesSubplot object. This in turn contains a XAxis and a YAxis object.

fig = plt.figure()
ax = fig.add_subplot(111)
x = ax.xaxis

print(type(ax))   # matplotlib.axes._subplots.AxesSubplot
print(type(x))    # matplotlib.axis.XAxis

XAxis is derived from base class Axis. AxesSubplot is derived from SubplotBase and Axes.

MB-F
  • 22,770
  • 4
  • 61
  • 116
4

Axes is just the plural form of axis. For example, x-axis and y-axis together can be called 2 axes or just axes. Subplots contain axes, for the most part. And a figure contains many subplots.

                      Figure
                        |
                        v
                ------------------
                |                |
                v                v
             Subplot1         Subplot2
                |                |
                v                v
               Axes             Axes
                |                |
                v                v
            ---------        -----------
            |       |        |         |
            v       v        v         v
          Axis1   Axis2    Axis1     Axis2                             
                         

KMA Badshah
  • 895
  • 8
  • 16