Matplotlib subplots vs axes vs axis (singular / plural)

后端 未结 2 752
别跟我提以往
别跟我提以往 2021-02-14 16:36

Can you please clarify some Matplotlib terminology:

  • is the word \"subplots\" (or \"subplot\"?) synonymous to \"axes\"?
  • what are singulars / plurals of \"a
2条回答
  •  余生分开走
    2021-02-14 16:45

    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))   # 
    
    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)) # 
    

    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)) # 
    

提交回复
热议问题