Matplotlib子图vs轴vs轴(单数/复数) [英] Matplotlib subplots vs axes vs axis (singular / plural)

查看:89
本文介绍了Matplotlib子图vs轴vs轴(单数/复数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

能否请您阐明一些Matplotlib术语:

Can you please clarify some Matplotlib terminology:

  • "subplots"(或"subplot")一词与"axes"同义吗?
  • 轴"和轴"的单数/复数是什么?

推荐答案

这确实是一个令人困惑的问题.

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.

在matplotlib中, matplotlib.axes._axes.Axes 对象通常简称为"axes".该对象包含一个 xaxis 和一个 yaxis,因此得名.但是说到那个物体,人们会称它为单数轴.其中一些仍然被称为轴.

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.

每个子图都是一个 Axes 对象,但是有 Axes 对象,它们不是 AxesSubplot 对象.例如通过子图机制创建的轴是 matplotlib.axes._subplots.AxesSubplot .这个类派生自 matplotlib.axes._axes.Axes,因此这个子图是一个轴.但是,您也可以通过不同的机制来创建轴,例如通过向图形添加轴,fig.add_axes().这将不是子图,而是轴 matplotlib.axes._axes.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'>

还有其他轴,例如插入轴mpl_toolkits.axes_grid1.parasite_axes.AxesHostAxes.该对象也称为轴.

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

这篇关于Matplotlib子图vs轴vs轴(单数/复数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆