matplotlib.figure.SubFigure.add_subplot#

SubFigure.add_subplot(*args, **kwargs)[源代码]#

将一个 Axes 添加到图形中作为子图布局的一部分。

调用签名:

add_subplot(nrows, ncols, index, **kwargs)
add_subplot(pos, **kwargs)
add_subplot(ax)
add_subplot()
参数:
*args : int, (int, int, index), 或 SubplotSpec, 默认: (1, 1, 1)int, (int, int, index), or SubplotSpec, default: (1, 1, 1)

由以下其中一个描述的子图的位置:

  • 三个整数(nrowsncolsindex)。子图将占据一个具有*nrows*行和*ncols*列的网格中的*index*位置。index*从左上角的1开始,并向右增加。*index*也可以是一个二元组,指定子图的(*firstlast)索引(基于1,并包括*last*),例如,``fig.add_subplot(3, 1, (1, 2))``创建一个跨越图表上部2/3的子图。

  • 一个三位整数。这些数字被解释为如果分别给出为三个个位整数,即 fig.add_subplot(235) 等同于 fig.add_subplot(2, 3, 5)。请注意,这只能用于不超过9个子图的情况。

  • 一个 SubplotSpec

在极少数情况下,add_subplot 可能会被调用,参数为一个已经在当前图形中创建但不在图形 Axes 列表中的子图 Axes 实例。

投影{None, 'aitoff', 'hammer', 'lambert', 'mollweide', 'polar', 'rectilinear', str}, 可选

子图的投影类型 (Axes)。str 是自定义投影的名称,参见 projections。默认值 None 会导致 'rectilinear' 投影。

极地bool, 默认值: False

如果为真,等同于 projection='polar'。

axes_class : Axes 的子类类型, 可选子类类型

被实例化的 axes.Axes 子类。此参数与 projectionpolar 不兼容。请参阅 axisartist 以获取示例。

sharex, sharey : Axes, 可选Axes,可选

使用 sharex 和/或 sharey 共享 x 或 y axis。轴将具有与共享的 Axes 相同的限制、刻度和比例。

标签str

返回的 Axes 的标签。

返回:
Axes

子图的轴。返回的轴实际上可以是子类的实例,例如用于极坐标的 projections.polar.PolarAxes

其他参数:
**kwargs

此方法还接受返回的 Axes 基类的关键字参数;除了 figure 参数。直角坐标系基类 Axes 的关键字参数可以在下表中找到,但如果使用其他投影,可能还会有其他关键字参数。

属性

描述

可调整

{'box', 'datalim'}

agg_filter

一个过滤函数,它接收一个 (m, n, 3) 的浮点数数组和一个 dpi 值,并返回一个 (m, n, 3) 数组和两个从图像左下角开始的偏移量

alpha

标量或无

锚点

(float, float){'C', 'SW', 'S', 'SE', 'E', 'NE', ...}

animated

布尔

aspect

{'auto', 'equal'} 或 float

autoscale_on

布尔

autoscalex_on

未知

autoscaley_on

未知

axes_locator

Callable[[Axes, Renderer], Bbox]

axisbelow

布尔值或 'line'

box_aspect

浮点数或无

clip_box

BboxBase 或 None

clip_on

布尔

clip_path

补丁或(路径,变换)或无

facecolor 或 fc

color

figure

FigureSubFigure

forward_navigation_events

布尔值或“自动”

frame_on

布尔

gid

str

in_layout

布尔

标签

对象

鼠标悬停

布尔

导航

布尔

navigate_mode

未知

path_effects

AbstractPathEffect 列表

picker

None 或 bool 或 float 或 callable

position

[左, 底, 宽, 高] 或 Bbox

prop_cycle

Cycler

rasterization_zorder

浮点数或无

光栅化

布尔

sketch_params

(scale: float, length: float, randomness: float)

snap

布尔值或无

subplotspec

未知

标题

str

transform

Transform

url

str

可见

布尔

xbound

(下限: 浮点数, 上限: 浮点数)

xlabel

str

xlim

(左: 浮点数, 右: 浮点数)

xmargin

浮点数大于 -0.5

xscale

未知

xticklabels

未知

xticks

未知

ybound

(下限: 浮点数, 上限: 浮点数)

ylabel

str

ylim

(底部: 浮点数, 顶部: 浮点数)

ymargin

浮点数大于 -0.5

yscale

未知

yticklabels

未知

yticks

未知

zorder

浮动

示例

fig = plt.figure()

fig.add_subplot(231)
ax1 = fig.add_subplot(2, 3, 1)  # equivalent but more general

fig.add_subplot(232, frameon=False)  # subplot with no frame
fig.add_subplot(233, projection='polar')  # polar subplot
fig.add_subplot(234, sharex=ax1)  # subplot sharing x-axis with ax1
fig.add_subplot(235, facecolor="red")  # red subplot

ax1.remove()  # delete ax1 from the figure
fig.add_subplot(ax1)  # add ax1 back to the figure