为什么在 plt.subplot(211) 中使用 211

Dan*_*Dan 6 python matplotlib

在我看到的 pyplot 文档中

plt.subplt(211) 与 subplot(2, 1, 1) 相同

我还看到 211 在其他地方使用。为什么特别使用这些数字而不是其他数字?

tmd*_*son 12

plt.subplot接受三个参数,行数 ( nrows)、列数 ( ncols) 和绘图编号。使用 3 位代码是为 when 提供的便利功能nrowsncols并且plot_number都是<10

所以,211等价于nrows=2, ncols=1, plot_number=1

从文档

返回由给定网格定义定位的子图轴。

典型的调用签名:

subplot(nrows, ncols, plot_number) 
Run Code Online (Sandbox Code Playgroud)

其中 nrows 和 ncols 用于在概念上将图形拆分为nrows * ncols子轴,并 plot_number用于标识此函数将在概念网格内创建的特定子图。plot_number从 1 开始,首先跨行递增,最大值为nrows * ncols.

nrowsncolsplot_number都小于 10的情况下,存在一个便利,例如可以给出一个 3 位数的数字,其中百代表nrows,十代表ncols ,单位代表plot_number。例如:

subplot(211)
Run Code Online (Sandbox Code Playgroud)

在图中生成一个子轴,它表示 2 行 x 1 列概念网格中的顶部图(即第一个)(实际上不存在网格,但从概念上讲,这是返回的子图的定位方式)。