matplotlib.figure.Figure#

class matplotlib.figure.Figure(figsize=None, dpi=None, *, facecolor=None, edgecolor=None, linewidth=0.0, frameon=None, subplotpars=None, tight_layout=None, constrained_layout=None, layout=None, **kwargs)[源]#

所有绘图元素的顶层容器。

有关类方法的索引,请参阅matplotlib.figure

属性:
patch

表示图形背景补丁的Rectangle实例。

suppressComposite

对于多张图像,图形将根据渲染器option_image_nocomposite函数生成复合图像。如果suppressComposite为布尔值,这将覆盖渲染器。

参数:
figsize浮点数2元组,默认值:rcParams["figure.figsize"] (默认值:[6.4, 4.8])

图形尺寸(宽度, 高度),单位英寸。

dpi浮点数,默认值:rcParams["figure.dpi"] (默认值:100.0)

每英寸点数。

facecolor默认值:rcParams["figure.facecolor"] (默认值:'white')

图形补丁的填充颜色。

edgecolor默认值:rcParams["figure.edgecolor"] (默认值:'white')

图形补丁的边框颜色。

linewidth浮点数

框架的线宽(即图形补丁的边缘线宽)。

frameon布尔值,默认值:rcParams["figure.frameon"] (默认值:True)

如果为False,则不绘制图形背景补丁。

subplotparsSubplotParams

子图参数。如果未给出,将使用默认子图参数rcParams["figure.subplot.*"]

tight_layout布尔值或字典,默认值:rcParams["figure.autolayout"] (默认值:False)

是否使用紧凑布局机制。请参阅set_tight_layout

不建议使用

不建议使用此参数。在tight_layout=True的常见情况下,请改用layout='tight',否则请使用set_tight_layout

constrained_layout布尔值,默认值:rcParams["figure.constrained_layout.use"] (默认值:False)

这等同于layout='constrained'

不建议使用

不建议使用此参数。请改用layout='constrained'

layout{'constrained', 'compressed', 'tight', 'none', LayoutEngine, None},默认值:None

用于定位绘图元素以避免重叠坐标轴装饰(标签、刻度等)的布局机制。请注意,布局管理器可能会带来显著的性能开销。

  • 'constrained':受约束布局求解器调整坐标轴大小以避免重叠的坐标轴装饰。它可以处理复杂的绘图布局和颜色条,因此推荐使用。

    有关示例,请参阅受约束布局指南

  • 'compressed':使用与'constrained'相同的算法,但移除固定宽高比坐标轴之间的额外空间。最适用于简单的坐标轴网格。

  • 'tight':使用紧凑布局机制。这是一种相对简单的算法,它调整子图参数,使装饰不重叠。

    有关示例,请参阅紧凑布局指南

  • 'none':不使用布局引擎。

  • 一个LayoutEngine实例。内置布局类包括ConstrainedLayoutEngineTightLayoutEngine,它们可以通过'constrained'和'tight'更方便地访问。传递实例允许第三方提供自己的布局引擎。

如果未给出,则退回到使用参数tight_layoutconstrained_layout,包括它们的配置默认值rcParams["figure.autolayout"](默认值:False)和rcParams["figure.constrained_layout.use"](默认值:False)。

其他参数:
**kwargsFigure属性,可选

属性

描述

agg_filter

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

alpha

浮点数或 None

animated

布尔值

canvas

FigureCanvas

clip_box

BboxBase 或 None

clip_on

布尔值

clip_path

Patch 或 (Path, Transform) 或 None

constrained_layout

未知

constrained_layout_pads

未知

dpi

浮点数

edgecolor

color

facecolor

color

figheight

浮点数

figure

未知

figwidth

浮点数

frameon

布尔值

gid

字符串

in_layout

布尔值

label

对象

layout_engine

{'constrained', 'compressed', 'tight', 'none', LayoutEngine, None}

linewidth

数值

mouseover

布尔值

path_effects

AbstractPathEffect列表

picker

None 或 布尔值 或 浮点数 或 可调用对象

rasterized

布尔值

size_inches

(浮点数, 浮点数) 或 浮点数

sketch_params

(scale: 浮点数, length: 浮点数, randomness: 浮点数)

snap

布尔值或 None

tight_layout

未知

transform

变换

url

字符串

visible

布尔值

zorder

浮点数