图形轴和子绘图轴之间的区别



我想知道是否有人能帮助理解子图。

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

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

有人能解释一下吗?

术语经常与图形窗口和子图形一起使用

图形包含一个或多个轴。轴包含x轴和y轴等
图形的解剖

图形窗口具有轴意味着什么

来自入门教程


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

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

多轴图形。

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

有一个x和y轴。

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

艺术家教程值得一读(以及其他教程(。

最新更新