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()
- 参数:
- *argsint, (int, int, index), 或
SubplotSpec
, 默认值: (1, 1, 1) 由以下之一描述的子图位置
三个整数 (nrows, ncols, index)。子图将占据一个具有 nrows 行和 ncols 列的网格中的 index 位置。index 从左上角开始计数,为 1,然后向右递增。index 也可以是一个二元组,指定子图的 (first, last) 索引(基于 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 实例。- projection{None, 'aitoff', 'hammer', 'lambert', 'mollweide', 'polar', 'rectilinear', str}, 可选
子图的投影类型 (
Axes
)。str 是自定义投影的名称,详见projections
。默认值 None 会生成 'rectilinear'(直角坐标系)投影。- polarbool, 默认值: False
如果为 True,相当于 projection='polar'。
- axes_class
Axes
的子类类型, 可选的 被实例化的
axes.Axes
子类。此参数与 projection 和 polar 不兼容。示例请参阅 axisartist。- sharex, sharey
Axes
, 可选的 与 sharex 和/或 sharey 共享 x 或 y
轴
。该轴将与共享 Axes 的轴具有相同的限制、刻度和比例。- labelstr
返回的 Axes 的标签。
- *argsint, (int, int, index), 或
- 返回:
Axes
子图的 Axes。返回的 Axes 实际上可以是子类的实例,例如用于极坐标投影的
projections.polar.PolarAxes
。
- 其他参数:
- **kwargs
此方法也接受返回的 Axes 基类的关键字参数;除了 figure 参数。直线坐标系基类
Axes
的关键字参数可以在下表中找到,但如果使用其他投影,则可能还有其他关键字参数。属性
描述
{'box', 'datalim'}
一个过滤函数,它接受一个 (m, n, 3) 浮点数组和一个 dpi 值,并返回一个 (m, n, 3) 数组以及图像左下角的两个偏移量
浮点数或 None
(float, float) 或 {'C', 'SW', 'S', 'SE', 'E', 'NE', ...}
布尔值
{'auto', 'equal'} 或 float
布尔值
未知
未知
Callable[[Axes, Renderer], Bbox]
布尔值 或 'line'
浮点数或 None
BboxBase
或 None布尔值
Patch 或 (Path, Transform) 或 None
bool 或 "auto"
布尔值
str
布尔值
object
布尔值
布尔值
未知
list of
AbstractPathEffect
None 或 布尔值 或 浮点数 或 可调用对象
[left, bottom, width, height] 或
Bbox
浮点数或 None
布尔值
(scale: 浮点数, length: 浮点数, randomness: 浮点数)
布尔值或 None
未知
str
str
布尔值
(lower: float, upper: float)
str
(left: float, right: float)
float 大于 -0.5
未知
未知
未知
(lower: float, upper: float)
str
(bottom: float, top: float)
float 大于 -0.5
未知
未知
未知
浮点数
示例
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