matplotlib.patches.FancyArrowPatch#

classmatplotlib.patches.FancyArrowPatch(posA=None,posB=None,*,path=None,arrowstyle='simple',connectionstyle='arc3',patchA=None,patchB=None,shrinkA=2,shrinkB=2,mutation_scale=1,mutation_aspect=1,**kwargs)[source]#

Bases:Patch

A fancy arrow patch.

It draws an arrow using theArrowStyle. It is primarily used by theannotate method. For most purposes, use the annotate method fordrawing arrows.

The head and tail positions are fixed at the specified start and end pointsof the arrow, but the size and shape (in display coordinates) of the arrowdoes not change when the axis is moved or zoomed.

Defining the arrow position and path

There are two ways to define the arrow position and path:

  • Start, end and connection:The typical approach is to define the start and end points of thearrow usingposA andposB. The curve between these two canfurther be configured usingconnectionstyle.

    If given, the arrow curve is clipped bypatchA andpatchB,allowing it to start/end at the border of these patches.Additionally, the arrow curve can be shortened byshrinkA andshrinkBto create a margin between start/end (after possible clipping) and thedrawn arrow.

  • path: Alternatively ifpath is provided, an arrow is drawn alongthis Path. In this case,connectionstyle,patchA,patchB,shrinkA, andshrinkB are ignored.

Styling

Thearrowstyle defines the styling of the arrow head, tail and shaft.The resulting arrows can be styled further by setting thePatchproperties such aslinewidth,color,facecolor,edgecoloretc. via keyword arguments.

Parameters:
posA, posB(float, float), optional

(x, y) coordinates of start and end point of the arrow.The actually drawn start and end positions may be modifiedthroughpatchA,patchB,shrinkA, andshrinkB.

posA,posB are exclusive ofpath.

pathPath, optional

If provided, an arrow is drawn along this path andpatchA,patchB,shrinkA, andshrinkB are ignored.

path is exclusive ofposA,posB.

arrowstylestr orArrowStyle, default: 'simple'

The styling of arrow head, tail and shaft. This can be

  • ArrowStyle or one of its subclasses

  • The shorthand string name (e.g. "->") as given in the table below,optionally containing a comma-separated list of style parameters,e.g. "->, head_length=10, head_width=5".

The style parameters are scaled bymutation_scale.

The following arrow styles are available. See alsoAnnotation arrow style reference.

Class

Name

Parameters

Curve

-

None

CurveA

<-

head_length=0.4, head_width=0.2, widthA=1.0, widthB=1.0, lengthA=0.2, lengthB=0.2, angleA=0, angleB=0, scaleA=None, scaleB=None

CurveB

->

head_length=0.4, head_width=0.2, widthA=1.0, widthB=1.0, lengthA=0.2, lengthB=0.2, angleA=0, angleB=0, scaleA=None, scaleB=None

CurveAB

<->

head_length=0.4, head_width=0.2, widthA=1.0, widthB=1.0, lengthA=0.2, lengthB=0.2, angleA=0, angleB=0, scaleA=None, scaleB=None

CurveFilledA

<|-

head_length=0.4, head_width=0.2, widthA=1.0, widthB=1.0, lengthA=0.2, lengthB=0.2, angleA=0, angleB=0, scaleA=None, scaleB=None

CurveFilledB

-|>

head_length=0.4, head_width=0.2, widthA=1.0, widthB=1.0, lengthA=0.2, lengthB=0.2, angleA=0, angleB=0, scaleA=None, scaleB=None

CurveFilledAB

<|-|>

head_length=0.4, head_width=0.2, widthA=1.0, widthB=1.0, lengthA=0.2, lengthB=0.2, angleA=0, angleB=0, scaleA=None, scaleB=None

BracketA

]-

widthA=1.0, lengthA=0.2, angleA=0

BracketB

-[

widthB=1.0, lengthB=0.2, angleB=0

BracketAB

]-[

widthA=1.0, lengthA=0.2, angleA=0, widthB=1.0, lengthB=0.2, angleB=0

BarAB

|-|

widthA=1.0, angleA=0, widthB=1.0, angleB=0

BracketCurve

]->

widthA=1.0, lengthA=0.2, angleA=None

CurveBracket

<-[

widthB=1.0, lengthB=0.2, angleB=None

Simple

simple

head_length=0.5, head_width=0.5, tail_width=0.2

Fancy

fancy

head_length=0.4, head_width=0.4, tail_width=0.4

Wedge

wedge

tail_width=0.3, shrink_factor=0.5

Only the styles<|-,-|>,<|-|>simple,fancyandwedge contain closed paths and can be filled.

connectionstylestr orConnectionStyle or None, optional, default: 'arc3'

ConnectionStyle with whichposA andposB are connected.This can be

  • ConnectionStyle or one of its subclasses

  • The shorthand string name as given in the table below, e.g. "arc3".

Class

Name

Parameters

Arc3

arc3

rad=0.0

Angle3

angle3

angleA=90, angleB=0

Angle

angle

angleA=90, angleB=0, rad=0.0

Arc

arc

angleA=0, angleB=0, armA=None, armB=None, rad=0.0

Bar

bar

armA=0.0, armB=0.0, fraction=0.3, angle=None

Ignored ifpath is provided.

patchA, patchBPatch, default: None

Optional Patches atposA andposB, respectively. If given,the arrow path is clipped by these patches such that head and tailare at the border of the patches.

Ignored ifpath is provided.

shrinkA, shrinkBfloat, default: 2

Shorten the arrow path atposA andposB by this amount in points.This allows to add a margin between the intended start/end points andthe arrow.

Ignored ifpath is provided.

mutation_scalefloat, default: 1

Value with which attributes ofarrowstyle (e.g.,head_length)will be scaled.

mutation_aspectNone or float, default: None

The height of the rectangle will be squeezed by this value beforethe mutation and the mutated box will be stretched by the inverseof it.

Other Parameters:
**kwargsPatch properties, optional

Here is a list of availablePatch 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

In contrast to other patches, the defaultcapstyle andjoinstyle forFancyArrowPatch are set to"round".

draw(renderer)[source]#

Draw the Artist (and its children) using the given renderer.

This has no effect if the artist is not visible (Artist.get_visiblereturns False).

Parameters:
rendererRendererBase subclass.

Notes

This method is overridden in the Artist subclasses.

get_arrowstyle()[source]#

Return the arrowstyle object.

get_connectionstyle()[source]#

Return theConnectionStyle used.

get_mutation_aspect()[source]#

Return the aspect ratio of the bbox mutation.

get_mutation_scale()[source]#

Return the mutation scale.

Returns:
scalar
get_path()[source]#

Return the path of the arrow in the data coordinates.

set(*,agg_filter=<UNSET>,alpha=<UNSET>,animated=<UNSET>,antialiased=<UNSET>,arrowstyle=<UNSET>,capstyle=<UNSET>,clip_box=<UNSET>,clip_on=<UNSET>,clip_path=<UNSET>,color=<UNSET>,connectionstyle=<UNSET>,edgecolor=<UNSET>,facecolor=<UNSET>,fill=<UNSET>,gid=<UNSET>,hatch=<UNSET>,hatch_linewidth=<UNSET>,hatchcolor=<UNSET>,in_layout=<UNSET>,joinstyle=<UNSET>,label=<UNSET>,linestyle=<UNSET>,linewidth=<UNSET>,mouseover=<UNSET>,mutation_aspect=<UNSET>,mutation_scale=<UNSET>,patchA=<UNSET>,patchB=<UNSET>,path_effects=<UNSET>,picker=<UNSET>,positions=<UNSET>,rasterized=<UNSET>,sketch_params=<UNSET>,snap=<UNSET>,transform=<UNSET>,url=<UNSET>,visible=<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

arrowstyle

[ '-' | '<-' | '->' | '<->' | '<|-' | '-|>' | '<|-|>' | ']-' | '-[' | ']-[' | '|-|' | ']->' | '<-[' | 'simple' | 'fancy' | 'wedge' ]

capstyle

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

clip_box

BboxBase or None

clip_on

bool

clip_path

Patch or (Path, Transform) or None

color

color

connectionstyle

[ 'arc3' | 'angle3' | 'angle' | 'arc' | 'bar' ]

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

mutation_aspect

float

mutation_scale

float

patchA

patches.Patch

patchB

patches.Patch

path_effects

list ofAbstractPathEffect

picker

None or bool or float or callable

positions

unknown

rasterized

bool

sketch_params

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

snap

bool or None

transform

Transform

url

str

visible

bool

zorder

float

set_arrowstyle(arrowstyle=None,**kwargs)[source]#

Set the arrow style, possibly with further attributes.

Attributes from the previous arrow style are not reused.

Without argument (or witharrowstyle=None), the available boxstyles are returned as a human-readable string.

Parameters:
arrowstylestr orArrowStyle

The style of the arrow: either aArrowStyle instance, or astring, which is the style name and optionally comma separatedattributes (e.g. "Fancy,head_length=0.2"). Such a string is used toconstruct aArrowStyle object, as documented in that class.

The following arrow styles are available:

Class

Name

Parameters

Curve

-

None

CurveA

<-

head_length=0.4, head_width=0.2, widthA=1.0, widthB=1.0, lengthA=0.2, lengthB=0.2, angleA=0, angleB=0, scaleA=None, scaleB=None

CurveB

->

head_length=0.4, head_width=0.2, widthA=1.0, widthB=1.0, lengthA=0.2, lengthB=0.2, angleA=0, angleB=0, scaleA=None, scaleB=None

CurveAB

<->

head_length=0.4, head_width=0.2, widthA=1.0, widthB=1.0, lengthA=0.2, lengthB=0.2, angleA=0, angleB=0, scaleA=None, scaleB=None

CurveFilledA

<|-

head_length=0.4, head_width=0.2, widthA=1.0, widthB=1.0, lengthA=0.2, lengthB=0.2, angleA=0, angleB=0, scaleA=None, scaleB=None

CurveFilledB

-|>

head_length=0.4, head_width=0.2, widthA=1.0, widthB=1.0, lengthA=0.2, lengthB=0.2, angleA=0, angleB=0, scaleA=None, scaleB=None

CurveFilledAB

<|-|>

head_length=0.4, head_width=0.2, widthA=1.0, widthB=1.0, lengthA=0.2, lengthB=0.2, angleA=0, angleB=0, scaleA=None, scaleB=None

BracketA

]-

widthA=1.0, lengthA=0.2, angleA=0

BracketB

-[

widthB=1.0, lengthB=0.2, angleB=0

BracketAB

]-[

widthA=1.0, lengthA=0.2, angleA=0, widthB=1.0, lengthB=0.2, angleB=0

BarAB

|-|

widthA=1.0, angleA=0, widthB=1.0, angleB=0

BracketCurve

]->

widthA=1.0, lengthA=0.2, angleA=None

CurveBracket

<-[

widthB=1.0, lengthB=0.2, angleB=None

Simple

simple

head_length=0.5, head_width=0.5, tail_width=0.2

Fancy

fancy

head_length=0.4, head_width=0.4, tail_width=0.4

Wedge

wedge

tail_width=0.3, shrink_factor=0.5

**kwargs

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

Examples

set_arrowstyle("Fancy,head_length=0.2")set_arrowstyle("fancy",head_length=0.2)
set_connectionstyle(connectionstyle=None,**kwargs)[source]#

Set the connection style, possibly with further attributes.

Attributes from the previous connection style are not reused.

Without argument (or withconnectionstyle=None), the available boxstyles are returned as a human-readable string.

Parameters:
connectionstylestr orConnectionStyle

The style of the connection: either aConnectionStyle instance,or a string, which is the style name and optionally comma separatedattributes (e.g. "Arc,armA=30,rad=10"). Such a string is used toconstruct aConnectionStyle object, as documented in that class.

The following connection styles are available:

Class

Name

Parameters

Arc3

arc3

rad=0.0

Angle3

angle3

angleA=90, angleB=0

Angle

angle

angleA=90, angleB=0, rad=0.0

Arc

arc

angleA=0, angleB=0, armA=None, armB=None, rad=0.0

Bar

bar

armA=0.0, armB=0.0, fraction=0.3, angle=None

**kwargs

Additional attributes for the connection style. See the table abovefor supported parameters.

Examples

set_connectionstyle("Arc,armA=30,rad=10")set_connectionstyle("arc",armA=30,rad=10)
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_patchA(patchA)[source]#

Set the tail patch.

Parameters:
patchApatches.Patch
set_patchB(patchB)[source]#

Set the head patch.

Parameters:
patchBpatches.Patch
set_positions(posA,posB)[source]#

Set the start and end positions of the connecting path.

Parameters:
posA, posBNone, tuple

(x, y) coordinates of arrow tail and arrow head respectively. IfNone use current value.

Examples usingmatplotlib.patches.FancyArrowPatch#

Multiple Axes animation

Multiple Axes animation

Bar of pie

Bar of pie

Arrow guide

Arrow guide

Angle annotations on bracket arrows

Angle annotations on bracket arrows

Annotations

Annotations