matplotlib.gridspec.GridSpecBase#

class matplotlib.gridspec.GridSpecBase(nrows, ncols, height_ratios=None, width_ratios=None)[源代码][源代码]#

基类:object

GridSpec 的基类,指定子图将放置的网格的几何形状。

参数:
nrows, ncols整数

网格的行数和列数。

width_ratios : 长度为 ncols 的类数组对象, 可选长度为的类数组

定义各列的相对宽度。每列的相对宽度为 width_ratios[i] / sum(width_ratios)。如果未指定,所有列将具有相同的宽度。

height_ratios : 长度为 nrows 的类数组对象, 可选长度为的类数组

定义行的相对高度。每行的高度为 height_ratios[i] / sum(height_ratios)。如果没有给出,所有行将具有相同的高度。

get_geometry()[源代码][源代码]#

返回一个包含网格中行数和列数的元组。

get_grid_positions(fig)[源代码][源代码]#

返回网格单元在图形坐标中的位置。

参数:
fig

应用网格的图形。子图参数(边距和子图之间的间距)取自 fig

返回:
底部, 顶部, 左侧, 右侧数组

网格单元在图形坐标中的底部、顶部、左侧、右侧位置。

get_height_ratios()[源代码][源代码]#

返回高度比。

如果没有显式设置高度比,则这是 None

get_subplot_params(figure=None)[源代码][源代码]#
get_width_ratios()[源代码][源代码]#

返回宽度比例。

如果没有显式设置宽度比,则为 None

property ncols#

网格中的列数。

new_subplotspec(loc, rowspan=1, colspan=1)[源代码][源代码]#

创建并返回一个 SubplotSpec 实例。

参数:
位置(整数, 整数)

子图在网格中的位置为 (行索引, 列索引)

rowspan, colspanint, 默认值: 1

子图应在网格中跨越的行数和列数。

property nrows#

网格中的行数。

set_height_ratios(height_ratios)[源代码][源代码]#

设置行的相对高度。

height_ratios 的长度必须为 nrows。每一行的相对高度为 height_ratios[i] / sum(height_ratios)

set_width_ratios(width_ratios)[源代码][源代码]#

设置列的相对宽度。

width_ratios 的长度必须为 ncols。每个列的相对宽度为 width_ratios[i] / sum(width_ratios)

subplots(*, sharex=False, sharey=False, squeeze=True, subplot_kw=None)[源代码][源代码]#

将此 GridSpec 指定的所有子图添加到其父图。

详细文档请参见 Figure.subplots

使用 matplotlib.gridspec.GridSpecBase 的示例#

使用约束布局调整轴的大小

Resize Axes with constrained layout

用于多列/行子图布局的网格规格

Gridspec for multi-column/row subplot layouts

嵌套的网格规格

Nested Gridspecs

GridSpec 演示

GridSpec demo

origin 和 extent 在 imshow 中

origin and extent in imshow

约束布局指南

Constrained layout guide

紧凑布局指南

Tight layout guide