matplotlib.pyplot.subplot

matplotlib.pyplot.subplot(*args, **kwargs)[源代码]

在当前图形中添加子批次。

包装材料 Figure.add_subplot 在“注释”一节中解释了不同的行为。

呼叫签名:

subplot(nrows, ncols, index, **kwargs)
subplot(pos, **kwargs)
subplot(**kwargs)
subplot(ax)
参数:
*args :int,(int,int, 指数SubplotSpec ,默认值:(1,1,1)内特,(内特,内特,

其中一个描述的子图的位置

  • 三个整数( 诺尔斯恩科斯指数 ). 子地块将接受 指数 在网格上的位置 诺尔斯 行和 恩科斯 柱。 指数 从左上角的1开始,向右增加。 指数 也可以是指定( 第一last )指数(以1为基础,包括 last )子地块的,例如。, fig.add_subplot(3, 1, (1, 2)) 生成一个子图,该子图跨越图形的上2/3。
  • 三位整数。这些数字被解释为三个独立的整数,即。 fig.add_subplot(235) 是一样的 fig.add_subplot(2, 3, 5) . 请注意,仅当子批次不超过9个时,才可以使用此选项。
  • A SubplotSpec .
projection无,'aitoff'、'hammer'、'lambert'、'mollweide'、'polar'、'rectlinear'、str,可选

子批次的投影类型 (Axesstr 是自定义投影的名称,请参见 projections . 默认的“无”将导致“直线”投影。

polarbool,默认值:False

如果为真,则相当于投影='polar'。

斯莱西Axes 可选可选轴

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

labelSTR

返回轴的标签。

返回:
axes.SubplotBase, or another subclass of Axes

子批次的轴。返回的axes基类取决于使用的投影。它是 Axes 如果使用直线投影 projections.polar.PolarAxes 如果使用极轴投影。然后,返回的轴是基类的子批子类。

其他参数:
**kwargs

此方法还接受返回的Axis基类的关键字参数;除了 图形 争论。直线基类的关键字参数 Axes 可以在下表中找到,但如果使用其他投影,也可能存在其他关键字参数。

财产 描述
adjustable 'box'、'datalim'
agg_filter 一种过滤函数,它接受一个(m,n,3)浮点数组和一个dpi值,并返回一个(m,n,3)数组。
alpha 浮动或无
anchor 2-浮点数或'c'、'sw'、's'、'se'、…
animated 布尔
aspect {auto}或num
autoscale_on 布尔
autoscalex_on 布尔
autoscaley_on 布尔
axes_locator 可赎回的 [[轴,渲染器]] Bbox
axisbelow 布尔或“线”
box_aspect 没有,或者是一个数字
clip_box Bbox
clip_on 布尔
clip_path 面片或(路径、变换)或无
contains 未知的
facecolor 或fc 颜色
figure Figure
frame_on 布尔
gid STR
in_layout 布尔
label 对象
navigate 布尔
navigate_mode 未知的
path_effects AbstractPathEffect
picker 无、布尔或可呼叫
position [左、下、宽、高] 或 Bbox
prop_cycle 未知的
rasterization_zorder 浮动或无
rasterized 布尔或无
sketch_params (比例:浮动,长度:浮动,随机性:浮动)
snap 布尔或无
title STR
transform Transform
url STR
visible 布尔
xbound 未知的
xlabel STR
xlim (底部:浮动,顶部:浮动)
xmargin 浮动大于-0.5
xscale “Linear”,“Log”,“SymLog”,“Logit”,…
xticklabels 未知的
xticks 未知的
ybound 未知的
ylabel STR
ylim (底部:浮动,顶部:浮动)
ymargin 浮动大于-0.5
yscale “Linear”,“Log”,“SymLog”,“Logit”,…
yticklabels 未知的
yticks 未知的
zorder 浮动

笔记

创建子批次将删除与之重叠的任何现有子批次(超出共享边界)::

import matplotlib.pyplot as plt
# plot a line, implicitly creating a subplot(111)
plt.plot([1, 2, 3])
# now create a subplot which represents the top plot of a grid
# with 2 rows and 1 column. Since this subplot will overlap the
# first, the plot (and its axes) previously created, will be removed
plt.subplot(211)

如果不希望此行为,请使用 Figure.add_subplot 方法或 pyplot.axes 而是函数。

如果数字已经有带键的子批次( args关键字参数 )然后它将简单地将该子批次置为当前并返回它。此行为已弃用。同时,如果您不希望这种行为(即,您想强制创建一个新的子批次),则必须使用一组唯一的arg和kwarg。轴 标签 为此,已公开了属性:如果要将两个相同的子批次添加到图中,请确保为它们提供唯一的标签。

在极少数情况下, add_subplot 可以用单个参数调用,子批次轴实例已在当前图中创建,但不在图的轴列表中。

实例

plt.subplot(221)

# equivalent but more general
ax1=plt.subplot(2, 2, 1)

# add a subplot with no frame
ax2=plt.subplot(222, frameon=False)

# add a polar subplot
plt.subplot(223, projection='polar')

# add a red subplot that shares the x-axis with ax1
plt.subplot(224, sharex=ax1, facecolor='red')

# delete ax2 from the figure
plt.delaxes(ax2)

# add ax2 to the figure again
plt.subplot(ax2)