matplotlib.offsetbox#

Inheritance diagram of matplotlib.offsetbox

用于 Artist 对象的容器类。

OffsetBox

本模块中定义的所有容器艺术家对象的基类。

AnchoredOffsetbox, AnchoredText

相对于父坐标轴或特定锚点,锚定并对齐任意 Artist 对象或文本。

DrawingArea

具有固定宽度和高度的容器。子项在容器内具有固定位置,并且可能会被裁剪。

HPacker, VPacker

用于垂直或水平布局其子项的容器。

PaddedBox

一个用于在 Artist 周围添加填充的容器。

TextArea

包含一个 Text 实例。

class matplotlib.offsetbox.AnchoredOffsetbox(loc, *, pad=0.4, borderpad=0.5, child=None, prop=None, frameon=True, bbox_to_anchor=None, bbox_transform=None, **kwargs)[source]#

基类: OffsetBox

根据位置 *loc* 放置的偏移框。

AnchoredOffsetbox 有一个子项。当需要多个子项时,请使用额外的 OffsetBox 将它们包含起来。默认情况下,偏移框会锚定在其父 Axes 对象上。您可以显式指定 *bbox_to_anchor*。

参数:
locstr

框的位置。有效位置为 'upper left'(左上)、'upper center'(中上)、'upper right'(右上)、'center left'(左中)、'center'(居中)、'center right'(右中)、'lower left'(左下)、'lower center'(中下)、'lower right'(右下)。为了向后兼容,也接受数值。详见 Legend 的 *loc* 参数。

padfloat, 默认值:0.4

子项周围的填充,作为字号的一部分。

borderpadfloat, 默认值:0.5

偏移框边框与 *bbox_to_anchor* 之间的填充。

childOffsetBox

将被锚定的框。

propFontProperties

这仅用作填充的参考。如果未给定,则使用 rcParams["legend.fontsize"] (默认值:'medium')。

frameonbool

是否在框周围绘制边框。

bbox_to_anchorBboxBase, 2元组, 或 4元组浮点数

与 *loc* 结合使用,用于定位图例的框。

bbox_transformNone 或 matplotlib.transforms.Transform

边界框 (*bbox_to_anchor*) 的变换。

**kwargs

所有其他参数将传递给 OffsetBox

备注

详见 Legend,了解锚定机制的详细说明。

codes = {'center': 10, 'center left': 6, 'center right': 7, 'lower center': 8, 'lower left': 3, 'lower right': 4, 'right': 5, 'upper center': 9, 'upper left': 2, 'upper right': 1}#
draw(renderer)[source]#

如有必要,更新子项的位置并将其绘制到给定的 *renderer*。

get_bbox(renderer)[source]#

返回偏移框的边界框,忽略父偏移。

get_bbox_to_anchor()[source]#

返回框所锚定到的边界框。

get_child()[source]#

返回子项。

get_children()[source]#

返回子项列表。

get_offset(bbox, renderer)[source]#

将偏移量作为元组 (x, y) 返回。

必须提供范围参数,以处理偏移量由可调用对象动态确定的情况(详见 set_offset)。

参数:
bboxBbox
rendererRendererBase 子类
set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, bbox_to_anchor=<UNSET>, child=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, gid=<UNSET>, height=<UNSET>, in_layout=<UNSET>, label=<UNSET>, mouseover=<UNSET>, offset=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, width=<UNSET>, zorder=<UNSET>)[source]#

一次性设置多个属性。

支持的属性包括:

属性

描述

agg_filter

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

alpha

浮点数或 None

animated

布尔值

bbox_to_anchor

未知

child

未知

clip_box

BboxBase 或 None

clip_on

布尔值

clip_path

Patch 或 (Path, Transform) 或 None

figure

Figure

gid

str

height

浮点数

in_layout

布尔值

label

object

mouseover

布尔值

offset

(float, float) 或 callable

path_effects

列表 AbstractPathEffect

picker

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

rasterized

布尔值

sketch_params

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

snap

布尔值或 None

transform

变换

url

str

visible

布尔值

width

浮点数

zorder

浮点数

set_bbox_to_anchor(bbox, transform=None)[source]#

设置框所锚定到的边界框。

*bbox* 可以是 Bbox 实例、[left, bottom, width, height] 列表,或者是 [left, bottom] 列表(其中宽度和高度假定为零)。边界框将通过给定变换转换为显示坐标。

set_child(child)[source]#

设置要锚定的子项。

update_frame(bbox, fontsize=None)[source]#
zorder = 5#
class matplotlib.offsetbox.AnchoredText(s, loc, *, pad=0.4, borderpad=0.5, prop=None, **kwargs)[source]#

基类: AnchoredOffsetbox

带有 Text 的 AnchoredOffsetbox。

参数:
sstr

文本。

locstr

位置代码。详见 AnchoredOffsetbox

padfloat, 默认值:0.4

文本周围的填充,作为字号的一部分。

borderpadfloat, 默认值:0.5

偏移框边框与 *bbox_to_anchor* 之间的间距。

propdict, 可选

要传递给 AnchoredText 中包含的 Text 实例的关键字参数字典。

**kwargs

所有其他参数将传递给 AnchoredOffsetbox

set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, bbox_to_anchor=<UNSET>, child=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, gid=<UNSET>, height=<UNSET>, in_layout=<UNSET>, label=<UNSET>, mouseover=<UNSET>, offset=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, width=<UNSET>, zorder=<UNSET>)[source]#

一次性设置多个属性。

支持的属性包括:

属性

描述

agg_filter

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

alpha

浮点数或 None

animated

布尔值

bbox_to_anchor

未知

child

未知

clip_box

BboxBase 或 None

clip_on

布尔值

clip_path

Patch 或 (Path, Transform) 或 None

figure

Figure

gid

str

height

浮点数

in_layout

布尔值

label

object

mouseover

布尔值

offset

(float, float) 或 callable

path_effects

列表 AbstractPathEffect

picker

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

rasterized

布尔值

sketch_params

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

snap

布尔值或 None

transform

变换

url

str

visible

布尔值

width

浮点数

zorder

浮点数

class matplotlib.offsetbox.AnnotationBbox(offsetbox, xy, xybox=None, xycoords='data', boxcoords=None, *, frameon=True, pad=0.4, annotation_clip=None, box_alignment=(0.5, 0.5), bboxprops=None, arrowprops=None, fontsize=None, **kwargs)[source]#

基类: Artist, _AnnotationBase

用于引用特定位置 *xy* 的 OffsetBox 容器。

可选地,可以绘制一个从偏移框指向 *xy* 的箭头。

这类似于 Annotation,但使用 OffsetBox 而非 Text

参数:
offsetboxOffsetBox
xy(float, float)

要标注的点 *(x, y)*。坐标系统由 *xycoords* 决定。

xybox(float, float), 默认值:*xy*

放置文本的位置 *(x, y)*。坐标系统由 *boxcoords* 确定。

xycoordsstr 的单个或两元组,或 Artist,或 Transform,或 callable, 默认值:'data'

给出 *xy* 的坐标系统。详见 Annotation 中的 *xycoords* 参数,了解详细说明。

boxcoordsstr 的单个或两元组,或 Artist,或 Transform,或 callable, 默认值:*xycoords* 的值

给出 *xybox* 的坐标系统。详见 Annotation 中的 *textcoords* 参数,了解详细说明。

frameonbool,默认值:True

默认情况下,文本周围环绕着一个白色 FancyBboxPatch(可作为 AnnotationBboxpatch 属性访问)。如果 *frameon* 设置为 False,则此补丁将不可见。

annotation_clip: bool 或 None, 默认值:None

当标注点 *xy* 在坐标系区域之外时,是否剪裁(即不绘制)标注。

  • 如果为 *True*,当 *xy* 在坐标系之外时,标注将被剪裁。

  • 如果为 *False*,标注将始终被绘制。

  • 如果为 *None*,当 *xy* 在坐标系之外且 *xycoords* 为 'data' 时,标注将被剪裁。

padfloat, 默认值:0.4

偏移框周围的填充。

box_alignment(float, float)

一个包含两个浮点数的元组,用于偏移框相对于 *boxcoords* 的垂直和水平对齐。左下角为 (0, 0),右上角为 (1, 1)。

bboxpropsdict, 可选

一个字典,用于设置注释边界框的属性,例如 *boxstyle* 和 *alpha*。详见 FancyBboxPatch

arrowprops: dict, 可选

箭头属性,详见 Annotation 中的描述。

fontsize: float 或 str, 可选

转换为点并作为 *mutation_scale* 传递给 FancyBboxPatch,以缩放框样式属性(例如 pad 或 rounding_size)。此名称的选择是类比于 Text,其中 *fontsize* 也定义了 mutation scale。如果未给定,则使用 rcParams["legend.fontsize"] (默认值:'medium')。详见 Text.set_fontsize,了解有效值。

**kwargs

其他 AnnotationBbox 属性。详见 AnnotationBbox.set,了解列表。

property anncoords#
contains(mouseevent)[source]#

测试艺术家是否包含鼠标事件。

参数:
mouseeventMouseEvent
返回:
contains布尔值

是否有任何值在半径范围内。

details字典

一个艺术家特定的字典,包含事件上下文的详细信息,例如哪些点包含在选择半径内。有关详细信息,请参阅各个 Artist 子类。

draw(renderer)[source]#

使用给定的渲染器绘制 Artist(及其子对象)。

如果艺术家不可见(Artist.get_visible 返回 False),此操作无效。

参数:
rendererRendererBase 子类。

备注

此方法在 Artist 子类中被覆盖。

get_children()[source]#

返回此 Artist 的子 Artist 列表。

get_fontsize()[source]#

返回字号(以点为单位)。

get_tightbbox(renderer=None)[source]#

类似于 Artist.get_window_extent,但包含任何裁剪。

参数:
rendererRendererBase 子类,可选

用于绘制图形的渲染器(即 fig.canvas.get_renderer()

返回:
Bbox 或 None

封闭的边界框(以图形像素坐标表示)。如果剪裁导致没有交集,则返回 None。

get_window_extent(renderer=None)[source]#

获取 artist 在显示空间中的边界框。

边界框的宽度和高度均为非负值。

子类应覆盖此方法,以便将其包含在边界框“紧密”计算中。默认返回一个位于 0, 0 的空边界框。

使用此函数时请小心,如果艺术家的窗口范围(artist window extent)发生变化,结果将不会更新。范围的变化可能是由于变换栈的任何变化引起的,例如改变坐标轴限制(Axes limits)、图形大小(figure size)或使用的画布(canvas)(例如保存图形时)。这可能导致意外行为,即交互式图形在屏幕上看起来正常,但保存时会出错。

set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, annotation_clip=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, fontsize=<UNSET>, gid=<UNSET>, in_layout=<UNSET>, label=<UNSET>, mouseover=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, zorder=<UNSET>)[source]#

一次性设置多个属性。

支持的属性包括:

属性

描述

agg_filter

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

alpha

浮点数或 None

animated

布尔值

annotation_clip

布尔值或 None

clip_box

BboxBase 或 None

clip_on

布尔值

clip_path

Patch 或 (Path, Transform) 或 None

figure

未知

fontsize

未知

gid

str

in_layout

布尔值

label

object

mouseover

布尔值

path_effects

列表 AbstractPathEffect

picker

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

rasterized

布尔值

sketch_params

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

snap

布尔值或 None

transform

变换

url

str

visible

布尔值

zorder

浮点数

set_figure(fig)[source]#

设置艺术家所属的 FigureSubFigure 实例。

参数:
figFigureSubFigure
set_fontsize(s=None)[source]#

以点为单位设置字体大小。

如果未给出 s,则重置为 rcParams["legend.fontsize"] (默认值:'medium')。

update_positions(renderer)[source]#

更新标注点、文本和箭头的像素位置。

property xyann#
zorder = 3#
class matplotlib.offsetbox.AuxTransformBox(aux_transform)[source]#

基类: OffsetBox

带有辅助变换(aux_transform)的偏移框。其子元素将首先进行辅助变换,然后进行偏移。辅助变换的绝对坐标具有意义,因为它将自动调整,以便在偏移变换之前,子元素的边界框的左下角被设置为(0, 0)。

它类似于绘图区域(drawing area),不同之处在于框的范围不是预先确定的,而是根据其子元素的窗口范围计算的。此外,子元素的范围将在变换后的坐标中计算。

add_artist(a)[source]#

向容器框添加一个 Artist

draw(renderer)[source]#

如有必要,更新子项的位置并将其绘制到给定的 *renderer*。

get_bbox(renderer)[source]#

返回偏移框的边界框,忽略父偏移。

get_offset()[source]#

返回容器的偏移量。

get_transform()[source]#

返回应用于子元素的 Transform

set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, gid=<UNSET>, height=<UNSET>, in_layout=<UNSET>, label=<UNSET>, mouseover=<UNSET>, offset=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, width=<UNSET>, zorder=<UNSET>)[source]#

一次性设置多个属性。

支持的属性包括:

属性

描述

agg_filter

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

alpha

浮点数或 None

animated

布尔值

clip_box

BboxBase 或 None

clip_on

布尔值

clip_path

Patch 或 (Path, Transform) 或 None

figure

Figure

gid

str

height

浮点数

in_layout

布尔值

label

object

mouseover

布尔值

offset

(浮点数, 浮点数)

path_effects

列表 AbstractPathEffect

picker

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

rasterized

布尔值

sketch_params

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

snap

布尔值或 None

transform

未知

url

str

visible

布尔值

width

浮点数

zorder

浮点数

set_offset(xy)[source]#

设置容器的偏移量。

参数:
xy(float, float)

偏移量在显示单位中的 (x, y) 坐标。

set_transform(t)[source]#

set_transform 被忽略。

class matplotlib.offsetbox.DraggableAnnotation(annotation, use_blit=False)[source]#

基类:DraggableBase

save_offset()[source]#
update_offset(dx, dy)[source]#
class matplotlib.offsetbox.DraggableBase(ref_artist, use_blit=False)[source]#

基类: object

可拖动艺术家(图例、偏移框)的辅助基类。

派生类必须重写以下方法

def save_offset(self):
    '''
    Called when the object is picked for dragging; should save the
    reference position of the artist.
    '''

def update_offset(self, dx, dy):
    '''
    Called during the dragging; (*dx*, *dy*) is the pixel offset from
    the point where the mouse drag started.
    '''

可选地,您可以重写以下方法

def finalize_offset(self):
    '''Called when the mouse is released.'''

DraggableLegendDraggableAnnotation 的当前实现中,update_offset 将艺术家放置在显示坐标中,而 finalize_offset 则重新计算它们在坐标轴坐标中的位置并设置相关属性。

property canvas#
property cids#
disconnect()[source]#

断开回调。

finalize_offset()[source]#
on_motion(evt)[source]#
on_pick(evt)[source]#
on_release(event)[source]#
save_offset()[source]#
update_offset(dx, dy)[source]#
class matplotlib.offsetbox.DraggableOffsetBox(ref_artist, offsetbox, use_blit=False)[source]#

基类:DraggableBase

get_loc_in_canvas()[source]#
save_offset()[source]#
update_offset(dx, dy)[source]#
class matplotlib.offsetbox.DrawingArea(width, height, xdescent=0.0, ydescent=0.0, clip=False)[source]#

基类: OffsetBox

DrawingArea 可以包含任何 Artist 作为子元素。DrawingArea 具有固定的宽度和高度。子元素相对于父元素的位置是固定的。子元素可以在父元素的边界处被裁剪。

参数:
width, height浮点型

容器框的宽度和高度。

xdescent, ydescent浮点型

框在x和y方向上的下沉量。

clip布尔型

是否将子元素裁剪到框的边界。

add_artist(a)[source]#

向容器框添加一个 Artist

property clip_children#

此 `DrawingArea` 的子元素是否应由 `DrawingArea` 边界框裁剪。

draw(renderer)[source]#

如有必要,更新子项的位置并将其绘制到给定的 *renderer*。

get_bbox(renderer)[source]#

返回偏移框的边界框,忽略父偏移。

get_offset()[source]#

返回容器的偏移量。

get_transform()[source]#

返回应用于子元素的 Transform

set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, gid=<UNSET>, height=<UNSET>, in_layout=<UNSET>, label=<UNSET>, mouseover=<UNSET>, offset=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, width=<UNSET>, zorder=<UNSET>)[source]#

一次性设置多个属性。

支持的属性包括:

属性

描述

agg_filter

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

alpha

浮点数或 None

animated

布尔值

clip_box

BboxBase 或 None

clip_on

布尔值

clip_path

Patch 或 (Path, Transform) 或 None

figure

Figure

gid

str

height

浮点数

in_layout

布尔值

label

object

mouseover

布尔值

offset

(浮点数, 浮点数)

path_effects

列表 AbstractPathEffect

picker

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

rasterized

布尔值

sketch_params

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

snap

布尔值或 None

transform

未知

url

str

visible

布尔值

width

浮点数

zorder

浮点数

set_offset(xy)[source]#

设置容器的偏移量。

参数:
xy(float, float)

偏移量在显示单位中的 (x, y) 坐标。

set_transform(t)[source]#

set_transform 被忽略。

class matplotlib.offsetbox.HPacker(pad=0.0, sep=0.0, width=None, height=None, align='baseline', mode='fixed', children=None)[source]#

基类:PackerBase

HPacker 水平排列其子元素,并在绘制时自动调整它们的相对位置。

+-------------------------------+
| Child 1    Child 2    Child 3 |
+-------------------------------+
参数:
pad浮点型,默认值:0.0

以点为单位的边界填充。

sep浮点型,默认值:0.0

以点为单位的项目间距。

width, height浮点型,可选

容器框的宽度和高度(像素),如果为 None 则计算。

align{'top', 'bottom', 'left', 'right', 'center', 'baseline'},默认值:'baseline'

框的对齐方式。

mode{'fixed', 'expand', 'equal'},默认值:'fixed'

打包模式。

  • 'fixed' 模式将给定的 Artists 紧密打包,并以 sep 间距隔开。

  • 'expand' 模式使用最大可用空间以等间距分布艺术家。

  • 'equal':每个艺术家占据可用空间的相等部分,并在此空间内左对齐(或顶部对齐)。

childrenArtist 列表

要打包的艺术家。

备注

padsep 以点为单位,并将根据渲染器 DPI 进行缩放,而 widthheight 以像素为单位。

set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, gid=<UNSET>, height=<UNSET>, in_layout=<UNSET>, label=<UNSET>, mouseover=<UNSET>, offset=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, width=<UNSET>, zorder=<UNSET>)[source]#

一次性设置多个属性。

支持的属性包括:

属性

描述

agg_filter

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

alpha

浮点数或 None

animated

布尔值

clip_box

BboxBase 或 None

clip_on

布尔值

clip_path

Patch 或 (Path, Transform) 或 None

figure

Figure

gid

str

height

浮点数

in_layout

布尔值

label

object

mouseover

布尔值

offset

(float, float) 或 callable

path_effects

列表 AbstractPathEffect

picker

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

rasterized

布尔值

sketch_params

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

snap

布尔值或 None

transform

变换

url

str

visible

布尔值

width

浮点数

zorder

浮点数

class matplotlib.offsetbox.OffsetBox(*args, **kwargs)[source]#

基类: Artist

OffsetBox 是一个简单的容器艺术家。

子艺术家应绘制在其父艺术家的相对位置。

作为一个艺术家本身,所有参数都会传递给 Artist

property axes#

艺术家所在的 Axes 实例,或 None

contains(mouseevent)[source]#

将鼠标事件的包含检查委托给子元素。

作为一个容器,OffsetBox 本身不响应鼠标事件。

参数:
mouseeventMouseEvent
返回:
contains布尔值

是否有任何值在半径范围内。

details字典

一个艺术家特定的字典,包含事件上下文的详细信息,例如哪些点包含在选择半径内。有关详细信息,请参阅各个 Artist 子类。

另请参阅

Artist.contains
draw(renderer)[source]#

如有必要,更新子项的位置并将其绘制到给定的 *renderer*。

get_bbox(renderer)[source]#

返回偏移框的边界框,忽略父偏移。

get_children()[source]#

返回子 Artists 的列表。

get_offset(bbox, renderer)[source]#

将偏移量作为元组 (x, y) 返回。

必须提供范围参数,以处理偏移量由可调用对象动态确定的情况(详见 set_offset)。

参数:
bboxBbox
rendererRendererBase 子类
get_visible_children()[source]#

返回可见子 Artists 的列表。

get_window_extent(renderer=None)[source]#

获取 artist 在显示空间中的边界框。

边界框的宽度和高度均为非负值。

子类应覆盖此方法,以便将其包含在边界框“紧密”计算中。默认返回一个位于 0, 0 的空边界框。

使用此函数时请小心,如果艺术家的窗口范围(artist window extent)发生变化,结果将不会更新。范围的变化可能是由于变换栈的任何变化引起的,例如改变坐标轴限制(Axes limits)、图形大小(figure size)或使用的画布(canvas)(例如保存图形时)。这可能导致意外行为,即交互式图形在屏幕上看起来正常,但保存时会出错。

set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, gid=<UNSET>, height=<UNSET>, in_layout=<UNSET>, label=<UNSET>, mouseover=<UNSET>, offset=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, width=<UNSET>, zorder=<UNSET>)[source]#

一次性设置多个属性。

支持的属性包括:

属性

描述

agg_filter

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

alpha

浮点数或 None

animated

布尔值

clip_box

BboxBase 或 None

clip_on

布尔值

clip_path

Patch 或 (Path, Transform) 或 None

figure

Figure

gid

str

height

浮点数

in_layout

布尔值

label

object

mouseover

布尔值

offset

(float, float) 或 callable

path_effects

列表 AbstractPathEffect

picker

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

rasterized

布尔值

sketch_params

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

snap

布尔值或 None

transform

变换

url

str

visible

布尔值

width

浮点数

zorder

浮点数

set_figure(fig)[source]#

OffsetBox 及其所有子元素设置 Figure

参数:
figFigure
set_height(height)[source]#

设置框的高度。

参数:
height浮点型
set_offset(xy)[source]#

设置偏移量。

参数:
xy(浮点型,浮点型) 或 可调用对象

偏移量在显示单位中的 (x, y) 坐标。可以明确地作为元组 (x, y) 给出,也可以提供一个将范围转换为偏移量的函数。此函数必须具有以下签名:

def offset(width, height, xdescent, ydescent, renderer) -> (float, float)
set_width(width)[source]#

设置框的宽度。

参数:
width浮点数
class matplotlib.offsetbox.OffsetImage(arr, *, zoom=1, cmap=None, norm=None, interpolation=None, origin=None, filternorm=True, filterrad=4.0, resample=False, dpi_cor=True, **kwargs)[source]#

基类: OffsetBox

draw(renderer)[source]#

如有必要,更新子项的位置并将其绘制到给定的 *renderer*。

get_bbox(renderer)[source]#

返回偏移框的边界框,忽略父偏移。

get_children()[source]#

返回子 Artists 的列表。

get_data()[source]#
get_offset()[source]#

返回容器的偏移量。

get_zoom()[source]#
set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, data=<UNSET>, gid=<UNSET>, height=<UNSET>, in_layout=<UNSET>, label=<UNSET>, mouseover=<UNSET>, offset=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, width=<UNSET>, zoom=<UNSET>, zorder=<UNSET>)[source]#

一次性设置多个属性。

支持的属性包括:

属性

描述

agg_filter

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

alpha

浮点数或 None

animated

布尔值

clip_box

BboxBase 或 None

clip_on

布尔值

clip_path

Patch 或 (Path, Transform) 或 None

data

未知

figure

Figure

gid

str

height

浮点数

in_layout

布尔值

label

object

mouseover

布尔值

offset

(float, float) 或 callable

path_effects

列表 AbstractPathEffect

picker

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

rasterized

布尔值

sketch_params

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

snap

布尔值或 None

transform

变换

url

str

visible

布尔值

width

浮点数

缩放

未知

zorder

浮点数

set_data(arr)[source]#
set_zoom(zoom)[source]#
class matplotlib.offsetbox.PackerBase(pad=0.0, sep=0.0, width=None, height=None, align='baseline', mode='fixed', children=None)[source]#

基类: OffsetBox

参数:
pad浮点型,默认值:0.0

以点为单位的边界填充。

sep浮点型,默认值:0.0

以点为单位的项目间距。

width, height浮点型,可选

容器框的宽度和高度(像素),如果为 None 则计算。

align{'top', 'bottom', 'left', 'right', 'center', 'baseline'},默认值:'baseline'

框的对齐方式。

mode{'fixed', 'expand', 'equal'},默认值:'fixed'

打包模式。

  • 'fixed' 模式将给定的 Artists 紧密打包,并以 sep 间距隔开。

  • 'expand' 模式使用最大可用空间以等间距分布艺术家。

  • 'equal':每个艺术家占据可用空间的相等部分,并在此空间内左对齐(或顶部对齐)。

childrenArtist 列表

要打包的艺术家。

备注

padsep 以点为单位,并将根据渲染器 DPI 进行缩放,而 widthheight 以像素为单位。

set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, gid=<UNSET>, height=<UNSET>, in_layout=<UNSET>, label=<UNSET>, mouseover=<UNSET>, offset=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, width=<UNSET>, zorder=<UNSET>)[source]#

一次性设置多个属性。

支持的属性包括:

属性

描述

agg_filter

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

alpha

浮点数或 None

animated

布尔值

clip_box

BboxBase 或 None

clip_on

布尔值

clip_path

Patch 或 (Path, Transform) 或 None

figure

Figure

gid

str

height

浮点数

in_layout

布尔值

label

object

mouseover

布尔值

offset

(float, float) 或 callable

path_effects

列表 AbstractPathEffect

picker

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

rasterized

布尔值

sketch_params

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

snap

布尔值或 None

transform

变换

url

str

visible

布尔值

width

浮点数

zorder

浮点数

class matplotlib.offsetbox.PaddedBox(child, pad=0.0, *, draw_frame=False, patch_attrs=None)[source]#

基类: OffsetBox

一个用于在 Artist 周围添加填充的容器。

PaddedBox 包含一个 FancyBboxPatch,在渲染时用于可视化它。

+----------------------------+
|                            |
|                            |
|                            |
| <--pad--> Artist           |
|             ^              |
|            pad             |
|             v              |
+----------------------------+
属性:
pad浮点数

以点为单位的填充。

patchFancyBboxPatch

draw_frame 为 True 时,此 FancyBboxPatch 将变得可见并在框周围创建边框。

参数:
childArtist

包含的 Artist

pad浮点型,默认值:0.0

以点为单位的填充。这将随渲染器 DPI 缩放。相反,widthheight像素 为单位,因此不缩放。

draw_frame布尔型

是否绘制包含的 FancyBboxPatch

patch_attrs字典 或 None

传递给包含的 FancyBboxPatch 的附加参数。

draw(renderer)[source]#

如有必要,更新子项的位置并将其绘制到给定的 *renderer*。

draw_frame(renderer)[source]#
set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, gid=<UNSET>, height=<UNSET>, in_layout=<UNSET>, label=<UNSET>, mouseover=<UNSET>, offset=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, width=<UNSET>, zorder=<UNSET>)[source]#

一次性设置多个属性。

支持的属性包括:

属性

描述

agg_filter

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

alpha

浮点数或 None

animated

布尔值

clip_box

BboxBase 或 None

clip_on

布尔值

clip_path

Patch 或 (Path, Transform) 或 None

figure

Figure

gid

str

height

浮点数

in_layout

布尔值

label

object

mouseover

布尔值

offset

(float, float) 或 callable

path_effects

列表 AbstractPathEffect

picker

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

rasterized

布尔值

sketch_params

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

snap

布尔值或 None

transform

变换

url

str

visible

布尔值

width

浮点数

zorder

浮点数

update_frame(bbox, fontsize=None)[source]#
class matplotlib.offsetbox.TextArea(s, *, textprops=None, multilinebaseline=False)[source]#

基类: OffsetBox

TextArea 是单个 Text 实例的容器艺术家。

文本默认以基线+左对齐方式放置在 (0, 0) 处。TextArea 实例的宽度和高度是其子文本的宽度和高度。

参数:
sstr

要显示的文本。

textprops字典,默认值:{}

要传递给 TextAreaText 实例的关键字参数字典。

multilinebaseline布尔型,默认值:False

是否调整多行文本的基线,使其(近似)与单行文本居中对齐。

draw(renderer)[source]#

如有必要,更新子项的位置并将其绘制到给定的 *renderer*。

get_bbox(renderer)[source]#

返回偏移框的边界框,忽略父偏移。

get_multilinebaseline()[source]#

获取多行基线。

get_offset()[source]#

返回容器的偏移量。

get_text()[source]#

返回此区域文本的字符串表示形式。

set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, gid=<UNSET>, height=<UNSET>, in_layout=<UNSET>, label=<UNSET>, mouseover=<UNSET>, multilinebaseline=<UNSET>, offset=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, text=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, width=<UNSET>, zorder=<UNSET>)[source]#

一次性设置多个属性。

支持的属性包括:

属性

描述

agg_filter

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

alpha

浮点数或 None

animated

布尔值

clip_box

BboxBase 或 None

clip_on

布尔值

clip_path

Patch 或 (Path, Transform) 或 None

figure

Figure

gid

str

height

浮点数

in_layout

布尔值

label

object

mouseover

布尔值

multilinebaseline

未知

offset

(浮点数, 浮点数)

path_effects

列表 AbstractPathEffect

picker

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

rasterized

布尔值

sketch_params

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

snap

布尔值或 None

text

未知

transform

未知

url

str

visible

布尔值

width

浮点数

zorder

浮点数

set_multilinebaseline(t)[source]#

设置多行基线。

如果为 True,则调整多行文本的基线,使其(近似)与单行文本居中对齐。这在图例实现中有所使用,例如,单行标签是基线对齐的,而多行标签则与它们“居中”对齐。

set_offset(xy)[source]#

设置容器的偏移量。

参数:
xy(float, float)

偏移量在显示单位中的 (x, y) 坐标。

set_text(s)[source]#

将此区域的文本设置为字符串。

set_transform(t)[source]#

set_transform 被忽略。

class matplotlib.offsetbox.VPacker(pad=0.0, sep=0.0, width=None, height=None, align='baseline', mode='fixed', children=None)[source]#

基类:PackerBase

VPacker 垂直排列其子元素,并在绘制时自动调整它们的相对位置。

+---------+
| Child 1 |
| Child 2 |
| Child 3 |
+---------+
参数:
pad浮点型,默认值:0.0

以点为单位的边界填充。

sep浮点型,默认值:0.0

以点为单位的项目间距。

width, height浮点型,可选

容器框的宽度和高度(像素),如果为 None 则计算。

align{'top', 'bottom', 'left', 'right', 'center', 'baseline'},默认值:'baseline'

框的对齐方式。

mode{'fixed', 'expand', 'equal'},默认值:'fixed'

打包模式。

  • 'fixed' 模式将给定的 Artists 紧密打包,并以 sep 间距隔开。

  • 'expand' 模式使用最大可用空间以等间距分布艺术家。

  • 'equal':每个艺术家占据可用空间的相等部分,并在此空间内左对齐(或顶部对齐)。

childrenArtist 列表

要打包的艺术家。

备注

padsep 以点为单位,并将根据渲染器 DPI 进行缩放,而 widthheight 以像素为单位。

set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, gid=<UNSET>, height=<UNSET>, in_layout=<UNSET>, label=<UNSET>, mouseover=<UNSET>, offset=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, width=<UNSET>, zorder=<UNSET>)[source]#

一次性设置多个属性。

支持的属性包括:

属性

描述

agg_filter

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

alpha

浮点数或 None

animated

布尔值

clip_box

BboxBase 或 None

clip_on

布尔值

clip_path

Patch 或 (Path, Transform) 或 None

figure

Figure

gid

str

height

浮点数

in_layout

布尔值

label

object

mouseover

布尔值

offset

(float, float) 或 callable

path_effects

列表 AbstractPathEffect

picker

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

rasterized

布尔值

sketch_params

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

snap

布尔值或 None

transform

变换

url

str

visible

布尔值

width

浮点数

zorder

浮点数