matplotlib.patches.FancyBboxPatch#

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

Bases:Patch

A fancy box around a rectangle with lower left atxy = (x,y)with specified width and height.

FancyBboxPatch is similar toRectangle, but it draws a fancy boxaround the rectangle. The transformation of the rectangle box to thefancy box is delegated to the style classes defined inBoxStyle.

Parameters:
xy(float, float)

The lower left corner of the box.

widthfloat

The width of the box.

heightfloat

The height of the box.

boxstylestr orBoxStyle

The style of the fancy box. This can either be aBoxStyleinstance or a string of the style name and optionally commaseparated attributes (e.g. "Round, pad=0.2"). This string ispassed toBoxStyle to construct aBoxStyle object. Seethere for a full documentation.

The following box styles are available:

Class

Name

Parameters

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, default: 1

Scaling factor applied to the attributes of the box style(e.g. pad or rounding_size).

mutation_aspectfloat, default: 1

The height of the rectangle will be squeezed by this value beforethe mutation and the mutated box will be stretched by the inverseof it. For example, this allows different horizontal and verticalpadding.

Other Parameters:
**kwargsPatch properties

Property

Description

agg_filter

a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image

alpha

unknown

animated

bool

antialiased oraa

bool or None

capstyle

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

clip_box

BboxBase or None

clip_on

bool

clip_path

Patch or (Path, Transform) or None

color

color

edgecolor orec

color or None

facecolor orfc

color or None

figure

Figure orSubFigure

fill

bool

gid

str

hatch

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

hatch_linewidth

unknown

hatchcolor

color or 'edge' or None

in_layout

bool

joinstyle

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

label

object

linestyle orls

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

linewidth orlw

float or None

mouseover

bool

path_effects

list ofAbstractPathEffect

picker

None or bool or float or callable

rasterized

bool

sketch_params

(scale: float, length: float, randomness: float)

snap

bool or None

transform

Transform

url

str

visible

bool

zorder

float

get_bbox()[source]#

Return theBbox.

get_boxstyle()[source]#

Return the boxstyle object.

get_height()[source]#

Return the height of the rectangle.

get_mutation_aspect()[source]#

Return the aspect ratio of the bbox mutation.

get_mutation_scale()[source]#

Return the mutation scale.

get_path()[source]#

Return the mutated path of the rectangle.

get_width()[source]#

Return the width of the rectangle.

get_x()[source]#

Return the left coord of the rectangle.

get_y()[source]#

Return the bottom coord of the rectangle.

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>,hatchcolor=<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]#

Set multiple properties at once.

Supported properties are

Property

Description

agg_filter

a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image

alpha

float or None

animated

bool

antialiased oraa

bool or None

bounds

unknown

boxstyle

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

capstyle

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

clip_box

BboxBase or None

clip_on

bool

clip_path

Patch or (Path, Transform) or None

color

color

edgecolor orec

color or None

facecolor orfc

color or None

figure

Figure orSubFigure

fill

bool

gid

str

hatch

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

hatch_linewidth

unknown

hatchcolor

color or 'edge' or None

height

float

in_layout

bool

joinstyle

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

label

object

linestyle orls

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

linewidth orlw

float or None

mouseover

bool

mutation_aspect

float

mutation_scale

float

path_effects

list ofAbstractPathEffect

picker

None or bool or float or callable

rasterized

bool

sketch_params

(scale: float, length: float, randomness: float)

snap

bool or None

transform

Transform

url

str

visible

bool

width

float

x

float

y

float

zorder

float

set_bounds(*args)[source]#

Set the bounds of the rectangle.

Call signatures:

set_bounds(left,bottom,width,height)set_bounds((left,bottom,width,height))
Parameters:
left, bottomfloat

The coordinates of the bottom left corner of the rectangle.

width, heightfloat

The width/height of the rectangle.

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

Set the box style, possibly with further attributes.

Attributes from the previous box style are not reused.

Without argument (or withboxstyle=None), the available box stylesare returned as a human-readable string.

Parameters:
boxstylestr orBoxStyle

The style of the box: either aBoxStyle instance, or a string,which is the style name and optionally comma separated attributes(e.g. "Round,pad=0.2"). Such a string is used to construct aBoxStyle object, as documented in that class.

The following box styles are available:

Class

Name

Parameters

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

Additional attributes for the box style. See the table above forsupported parameters.

Examples

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

Set the rectangle height.

Parameters:
hfloat
set_mutation_aspect(aspect)[source]#

Set the aspect ratio of the bbox mutation.

Parameters:
aspectfloat
set_mutation_scale(scale)[source]#

Set the mutation scale.

Parameters:
scalefloat
set_width(w)[source]#

Set the rectangle width.

Parameters:
wfloat
set_x(x)[source]#

Set the left coord of the rectangle.

Parameters:
xfloat
set_y(y)[source]#

Set the bottom coord of the rectangle.

Parameters:
yfloat

Examples usingmatplotlib.patches.FancyBboxPatch#

Reference for Matplotlib artists

Reference for Matplotlib artists

Drawing fancy boxes

Drawing fancy boxes