Matplotlib sub-pads versus axes versus axis (singular / plural)
This is a really confusing question.
In English, the axis is special, and the plural is the axis. The two axes of the view form two axes.
In matplotlib, an object is matplotlib.axes._axes.Axes
often simply called "axes". This object includes xaxis and yaxis, thus the name. But speaking of this object, one could call it axes in the singular. Some of them are still called axes.
Each subtask is an object Axes
, but there are objects Axes
that are not objects AxesSubplot
. ... the axes that are created through the subtask mechanism are matplotlib.axes._subplots.AxesSubplot
. This class comes from matplotlib.axes._axes.Axes
, so this subplot is axes. However, you can also create axes using different mechanisms, for example. adding axis to the drawing fig.add_axes()
. Then it will not be subtitled, and axis 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, e.g., insertion axis
mpl_toolkits.axes_grid1.parasite_axes.AxesHostAxes
. This object will 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'>
source to share
Axes are the plural of an axis. A sub typically has an x - axis and a y-axis , which together form two subheading axes .
Speak in terms of function / class names:
Figure.add_subplot
or pyplot.subplot
return an object AxesSubplot
. This, in turn, contains the object XAxis
and YAxis
.
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
derived from the base class Axis
.
AxesSubplot
is derived from SubplotBase
and Axes
.
source to share