【问题标题】:Difference Between Figure Axis and Sub Plot Axis?图轴和子图轴的区别?
【发布时间】:2020-08-21 17:33:46
【问题描述】:

我想知道是否有人可以帮助理解子情节。

轴这个词经常与图形窗口和子图一起使用,我想了解子图的轴和图形窗口的轴之间是否存在技术差异。

如果我有一个 2 x 2 图形,允许我绘制 4 个子图,那么每个子图将有自己的 X*Y 轴,但是图形窗口有一个轴意味着什么?

谁能解释一下?

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    轴这个词经常与图形窗口和子图一起使用

    一个图形包含一个或多个轴。 Axes 包含 x 轴和 y 轴等。
    Anatomy of a figure

    图形窗口有轴是什么意思

    来自Introductory Tutorial

    轴
    这就是您认为的“绘图”,它是具有数据空间的图像区域。一个给定的图形可以包含多个 Axes,但一个给定的 Axes 对象只能在一个图形中。 Axes 包含两个(或在 3D 的情况下为三个)Axis 对象(注意 Axes 和 Axis 之间的区别)...

    一个图形有一个或多个轴。无论是子图轴还是没有子图的图形的轴,轴都是相同的类型。

    具有多个轴的图形。

    >>> import matplotlib as mpl
    >>> from matplotlib import pyplot as plt
    
    >>> fig,ax = plt.subplots(2,2)
    >>> fig
    <Figure size 640x480 with 4 Axes>
    >>> ax
    array([[<matplotlib.axes._subplots.AxesSubplot object at 0x0000025A6AC707F0>,
            <matplotlib.axes._subplots.AxesSubplot object at 0x0000025A79F52A60>],
           [<matplotlib.axes._subplots.AxesSubplot object at 0x0000025A7E960A90>,
            <matplotlib.axes._subplots.AxesSubplot object at 0x0000025A7E98C040>]],
          dtype=object)
    >>> fig.axes
    [<matplotlib.axes._subplots.AxesSubplot object at 0x0000025A6AC707F0>, <matplotlib.axes._subplots.AxesSubplot object at 0x0000025A79F52A60>, <matplotlib.axes._subplots.AxesSubplot object at 0x0000025A7E960A90>, <matplotlib.axes._subplots.AxesSubplot object at 0x0000025A7E98C040>]
    >>>
    

    一个轴的图形。

    >>> fig,ax = plt.subplots()
    >>> ax
    <matplotlib.axes._subplots.AxesSubplot object at 0x0000025A678746A0>
    >>> fig.axes
    [<matplotlib.axes._subplots.AxesSubplot object at 0x0000025A678746A0>]
    >>>
    >>> isinstance(fig.axes[0],mpl.axes.Axes)
    True
    

    带有一个轴的图形。使用pyplot 制作绘图,然后获取当前图形和轴。

    >>> lines = plt.plot([1,2,3,4,5])
    >>> lines
    [<matplotlib.lines.Line2D object at 0x0000025A67857C10>]
    >>> fig = plt.gcf()
    >>> fig.axes
    [<matplotlib.axes._subplots.AxesSubplot object at 0x0000025A678746A0>]
    >>> plt.gca()
    <matplotlib.axes._subplots.AxesSubplot object at 0x0000025A678746A0>
    >>>
    

    Axes 有一个 x 和 y Axis。

    >>> ax = plt.gca()
    >>> ax.xaxis
    <matplotlib.axis.XAxis object at 0x0000025A67874AF0>
    >>> ax.yaxis
    <matplotlib.axis.YAxis object at 0x0000025A67861370>
    >>>
    >>> isinstance(ax.xaxis,mpl.axis.Axis)
    True
    

    Artist tutorial 值得一读(以及其他教程)。

    【讨论】:

      猜你喜欢
      • 2011-07-31
      • 2016-10-16
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多