matplotlib.patches.FancyBboxPatch#

class matplotlib.patches.FancyBboxPatch(xy, width, height, boxstyle='round', *, mutation_scale=1, mutation_aspect=1, **kwargs)[source]#

基类:Patch

一个花式方框,围绕着左下角位于 xy = (x, y) 且具有指定宽度和高度的矩形。

FancyBboxPatch 类似于 Rectangle,但它在矩形周围绘制一个花式方框。矩形框到花式框的变换委托给 BoxStyle 中定义的样式类。

参数:
xy(float, float)

方框的左下角。

width浮点数

方框的宽度。

heightfloat

方框的高度。

boxstylestr 或 BoxStyle

花式方框的样式。这可以是 BoxStyle 实例,或者是样式名称的字符串,以及可选的逗号分隔属性(例如 "Round, pad=0.2")。此字符串将传递给 BoxStyle 以构建一个 BoxStyle 对象。有关完整文档,请参阅该处。

以下方框样式可用:

名称

参数

Square

square

pad=0.3

Circle

circle

pad=0.3

Ellipse

ellipse

pad=0.3

LArrow

larrow

pad=0.3

RArrow

rarrow

pad=0.3

DArrow

darrow

pad=0.3

Round

round

pad=0.3, rounding_size=None

Round4

round4

pad=0.3, rounding_size=None

Sawtooth

sawtooth

pad=0.3, tooth_size=None

Roundtooth

roundtooth

pad=0.3, tooth_size=None

mutation_scalefloat, 默认: 1

应用于方框样式属性(例如 pad 或 rounding_size)的缩放因子。

mutation_aspectfloat, 默认: 1

矩形的高度将在变异前被此值压缩,变异后的方框将按其倒数拉伸。例如,这允许不同的水平和垂直填充。

其他参数:
**kwargsPatch 属性

属性

描述

agg_filter

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

alpha

未知

animated

布尔值

antialiasedaa

布尔值或 None

capstyle

CapStyle 或 {'butt', 'projecting', 'round'}

clip_box

BboxBase 或 None

clip_on

布尔值

clip_path

Patch 或 (Path, Transform) 或 None

color

color

edgecolorec

颜色 或 None

facecolorfc

颜色 或 None

figure

FigureSubFigure

fill

布尔值

gid

str

hatch

{'/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}

hatch_linewidth

未知

in_layout

布尔值

joinstyle

JoinStyle 或 {'miter', 'round', 'bevel'}

label

object

linestylels

{'-', '--', '-.', ':', '', (offset, on-off-seq), ...}

linewidthlw

浮点数或 None

mouseover

布尔值

path_effects

list of AbstractPathEffect

picker

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

rasterized

布尔值

sketch_params

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

snap

布尔值或 None

transform

变换

url

str

visible

布尔值

zorder

浮点数

get_bbox()[source]#

返回 Bbox

get_boxstyle()[source]#

返回方框样式对象。

get_height()[source]#

返回矩形的高度。

get_mutation_aspect()[source]#

返回 bbox 变异的纵横比。

get_mutation_scale()[source]#

返回变异比例。

get_path()[source]#

返回矩形的变异路径。

get_width()[source]#

返回矩形的宽度。

get_x()[source]#

返回矩形的左侧坐标。

get_y()[source]#

返回矩形的底部坐标。

set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, antialiased=<UNSET>, bounds=<UNSET>, boxstyle=<UNSET>, capstyle=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, color=<UNSET>, edgecolor=<UNSET>, facecolor=<UNSET>, fill=<UNSET>, gid=<UNSET>, hatch=<UNSET>, hatch_linewidth=<UNSET>, height=<UNSET>, in_layout=<UNSET>, joinstyle=<UNSET>, label=<UNSET>, linestyle=<UNSET>, linewidth=<UNSET>, mouseover=<UNSET>, mutation_aspect=<UNSET>, mutation_scale=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, width=<UNSET>, x=<UNSET>, y=<UNSET>, zorder=<UNSET>)[source]#

一次性设置多个属性。

支持的属性包括:

属性

描述

agg_filter

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

alpha

浮点数或 None

animated

布尔值

antialiasedaa

布尔值或 None

bounds

未知

boxstyle

[ 'square' | 'circle' | 'ellipse' | 'larrow' | 'rarrow' | 'darrow' | 'round' | 'round4' | 'sawtooth' | 'roundtooth' ]

capstyle

CapStyle 或 {'butt', 'projecting', 'round'}

clip_box

BboxBase 或 None

clip_on

布尔值

clip_path

Patch 或 (Path, Transform) 或 None

color

color

edgecolorec

颜色 或 None

facecolorfc

颜色 或 None

figure

FigureSubFigure

fill

布尔值

gid

str

hatch

{'/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}

hatch_linewidth

未知

height

浮点数

in_layout

布尔值

joinstyle

JoinStyle 或 {'miter', 'round', 'bevel'}

label

object

linestylels

{'-', '--', '-.', ':', '', (offset, on-off-seq), ...}

linewidthlw

浮点数或 None

mouseover

布尔值

mutation_aspect

浮点数

mutation_scale

浮点数

path_effects

list of AbstractPathEffect

picker

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

rasterized

布尔值

sketch_params

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

snap

布尔值或 None

transform

变换

url

str

visible

布尔值

width

浮点数

x

浮点数

y

浮点数

zorder

浮点数

set_bounds(*args)[source]#

设置矩形的边界。

调用签名

set_bounds(left, bottom, width, height)
set_bounds((left, bottom, width, height))
参数:
left, bottomfloat

矩形左下角的坐标。

width, heightfloat

矩形的宽度/高度。

set_boxstyle(boxstyle=None, **kwargs)[source]#

设置方框样式,可能带有附加属性。

不会重用之前方框样式中的属性。

无参数(或 boxstyle=None)时,将以人类可读的字符串形式返回可用方框样式。

参数:
boxstylestr 或 BoxStyle

方框的样式:可以是 BoxStyle 实例,也可以是样式名称的字符串,以及可选的逗号分隔属性(例如 "Round,pad=0.2")。此类字符串用于构造 BoxStyle 对象,如该类文档中所述。

以下方框样式可用:

名称

参数

Square

square

pad=0.3

Circle

circle

pad=0.3

Ellipse

ellipse

pad=0.3

LArrow

larrow

pad=0.3

RArrow

rarrow

pad=0.3

DArrow

darrow

pad=0.3

Round

round

pad=0.3, rounding_size=None

Round4

round4

pad=0.3, rounding_size=None

Sawtooth

sawtooth

pad=0.3, tooth_size=None

Roundtooth

roundtooth

pad=0.3, tooth_size=None

**kwargs

方框样式的附加属性。支持的参数请参见上表。

示例

set_boxstyle("Round,pad=0.2")
set_boxstyle("round", pad=0.2)
set_height(h)[source]#

设置矩形高度。

参数:
hfloat
set_mutation_aspect(aspect)[source]#

设置 bbox 变异的纵横比。

参数:
aspectfloat
set_mutation_scale(scale)[source]#

设置变异比例。

参数:
scale浮点数
set_width(w)[source]#

设置矩形宽度。

参数:
wfloat
set_x(x)[source]#

设置矩形的左侧坐标。

参数:
x浮点数
set_y(y)[source]#

设置矩形的底部坐标。

参数:
y浮点数

使用 matplotlib.patches.FancyBboxPatch 的示例#

Matplotlib 艺术家参考

Matplotlib 艺术家参考

绘制花式框

绘制花式框