matplotlib.patches.Patch#

classmatplotlib.patches.Patch(*,edgecolor=None,facecolor=None,color=None,linewidth=None,linestyle=None,antialiased=None,hatch=None,fill=True,capstyle=None,joinstyle=None,**kwargs)[source]#

Bases:Artist

A patch is a 2D artist with a face color and an edge color.

If any ofedgecolor,facecolor,linewidth, orantialiasedareNone, they default to their rc params setting.

The following kwarg properties are supported

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

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

contains(mouseevent,radius=None)[source]#

Test whether the mouse event occurred in the patch.

Parameters:
mouseeventMouseEvent

Where the user clicked.

radiusfloat, optional

Additional margin on the patch in target coordinates ofPatch.get_transform. SeePath.contains_point for furtherdetails.

IfNone, the default value depends on the state of the object:

  • IfArtist.get_picker is a number, the defaultis that value. This is so that picking works as expected.

  • Otherwise if the edge color has a non-zero alpha, the defaultis half of the linewidth. This is so that all the coloredpixels are "in" the patch.

  • Finally, if the edge has 0 alpha, the default is 0. This isso that patches without a stroked edge do not have pointsoutside of the filled region report as "in" due to aninvisible edge.

Returns:
(bool, empty dict)
contains_point(point,radius=None)[source]#

Return whether the given point is inside the patch.

Parameters:
point(float, float)

The point (x, y) to check, in target coordinates of.Patch.get_transform(). These are display coordinates for patchesthat are added to a figure or Axes.

radiusfloat, optional

Additional margin on the patch in target coordinates ofPatch.get_transform. SeePath.contains_point for furtherdetails.

IfNone, the default value depends on the state of the object:

  • IfArtist.get_picker is a number, the defaultis that value. This is so that picking works as expected.

  • Otherwise if the edge color has a non-zero alpha, the defaultis half of the linewidth. This is so that all the coloredpixels are "in" the patch.

  • Finally, if the edge has 0 alpha, the default is 0. This isso that patches without a stroked edge do not have pointsoutside of the filled region report as "in" due to aninvisible edge.

Returns:
bool

Notes

The proper use of this method depends on the transform of the patch.Isolated patches do not have a transform. In this case, the patchcreation coordinates and the point coordinates match. The followingexample checks that the center of a circle is within the circle

>>>center=0,0>>>c=Circle(center,radius=1)>>>c.contains_point(center)True

The convention of checking against the transformed patch stems fromthe fact that this method is predominantly used to check if displaycoordinates (e.g. from mouse events) are within the patch. If you wantto do the above check with data coordinates, you have to properlytransform them first:

>>>center=0,0>>>c=Circle(center,radius=3)>>>plt.gca().add_patch(c)>>>transformed_interior_point=c.get_data_transform().transform((0,2))>>>c.contains_point(transformed_interior_point)True
contains_points(points,radius=None)[source]#

Return whether the given points are inside the patch.

Parameters:
points(N, 2) array

The points to check, in target coordinates ofself.get_transform(). These are display coordinates for patchesthat are added to a figure or Axes. Columns contain x and y values.

radiusfloat, optional

Additional margin on the patch in target coordinates ofPatch.get_transform. SeePath.contains_point for furtherdetails.

IfNone, the default value depends on the state of the object:

  • IfArtist.get_picker is a number, the defaultis that value. This is so that picking works as expected.

  • Otherwise if the edge color has a non-zero alpha, the defaultis half of the linewidth. This is so that all the coloredpixels are "in" the patch.

  • Finally, if the edge has 0 alpha, the default is 0. This isso that patches without a stroked edge do not have pointsoutside of the filled region report as "in" due to aninvisible edge.

Returns:
length-N bool array

Notes

The proper use of this method depends on the transform of the patch.See the notes onPatch.contains_point.

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.

propertyfill#

Return whether the patch is filled.

get_aa()[source]#

Alias forget_antialiased.

get_antialiased()[source]#

Return whether antialiasing is used for drawing.

get_capstyle()[source]#

Return the capstyle.

get_data_transform()[source]#

Return theTransform mapping data coordinates tophysical coordinates.

get_ec()[source]#

Alias forget_edgecolor.

get_edgecolor()[source]#

Return the edge color.

get_extents()[source]#

Return thePatch's axis-aligned extents as aBbox.

get_facecolor()[source]#

Return the face color.

get_fc()[source]#

Alias forget_facecolor.

get_fill()[source]#

Return whether the patch is filled.

get_hatch()[source]#

Return the hatching pattern.

get_hatch_linewidth()[source]#

Return the hatch linewidth.

get_joinstyle()[source]#

Return the joinstyle.

get_linestyle()[source]#

Return the linestyle.

get_linewidth()[source]#

Return the line width in points.

get_ls()[source]#

Alias forget_linestyle.

get_lw()[source]#

Alias forget_linewidth.

get_patch_transform()[source]#

Return theTransform instance mapping patch coordinatesto data coordinates.

For example, one may define a patch of a circle which represents aradius of 5 by providing coordinates for a unit circle, and atransform which scales the coordinates (the patch coordinate) by 5.

get_path()[source]#

Return the path of this patch.

get_transform()[source]#

Return theTransform applied to thePatch.

get_verts()[source]#

Return a copy of the vertices used in this patch.

If the patch contains Bézier curves, the curves will be interpolated byline segments. To access the curves as curves, useget_path.

get_window_extent(renderer=None)[source]#

Get the artist's bounding box in display space.

The bounding box' width and height are nonnegative.

Subclasses should override for inclusion in the bounding box"tight" calculation. Default is to return an empty boundingbox at 0, 0.

Be careful when using this function, the results will not updateif the artist window extent of the artist changes. The extentcan change due to any changes in the transform stack, such aschanging the Axes limits, the figure size, or the canvas used(as is done when saving a figure). This can lead to unexpectedbehavior where interactive figures will look fine on the screen,but will save incorrectly.

set(*,agg_filter=<UNSET>,alpha=<UNSET>,animated=<UNSET>,antialiased=<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>,in_layout=<UNSET>,joinstyle=<UNSET>,label=<UNSET>,linestyle=<UNSET>,linewidth=<UNSET>,mouseover=<UNSET>,path_effects=<UNSET>,picker=<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

unknown

animated

bool

antialiased

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

color or None

facecolor

color or None

figure

Figure orSubFigure

fill

bool

gid

str

hatch

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

hatch_linewidth

unknown

in_layout

bool

joinstyle

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

label

object

linestyle

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

linewidth

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

set_aa(aa)[source]#

Alias forset_antialiased.

set_alpha(alpha)[source]#

Set the alpha value used for blending - not supported on all backends.

Parameters:
alphafloat or None

alpha must be within the 0-1 range, inclusive.

set_antialiased(aa)[source]#

Set whether to use antialiased rendering.

Parameters:
aabool or None
set_capstyle(s)[source]#

Set theCapStyle.

The default capstyle is 'round' forFancyArrowPatch and 'butt' forall other patches.

Parameters:
sCapStyle or {'butt', 'projecting', 'round'}
set_color(c)[source]#

Set both the edgecolor and the facecolor.

Parameters:
ccolor

See also

Patch.set_facecolor,Patch.set_edgecolor

For setting the edge or face color individually.

set_ec(color)[source]#

Alias forset_edgecolor.

set_edgecolor(color)[source]#

Set the patch edge color.

Parameters:
colorcolor or None
set_facecolor(color)[source]#

Set the patch face color.

Parameters:
colorcolor or None
set_fc(color)[source]#

Alias forset_facecolor.

set_fill(b)[source]#

Set whether to fill the patch.

Parameters:
bbool
set_hatch(hatch)[source]#

Set the hatching pattern.

hatch can be one of:

/-diagonalhatching\-backdiagonal|-vertical--horizontal+-crossedx-crosseddiagonalo-smallcircleO-largecircle.-dots*-stars

Letters can be combined, in which case all the specifiedhatchings are done. If same letter repeats, it increases thedensity of hatching of that pattern.

Parameters:
hatch{'/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}
set_hatch_linewidth(lw)[source]#

Set the hatch linewidth.

set_joinstyle(s)[source]#

Set theJoinStyle.

The default joinstyle is 'round' forFancyArrowPatch and 'miter' forall other patches.

Parameters:
sJoinStyle or {'miter', 'round', 'bevel'}
set_linestyle(ls)[source]#

Set the patch linestyle.

linestyle

description

'-' or'solid'

solid line

'--' or'dashed'

dashed line

'-.' or'dashdot'

dash-dotted line

':' or'dotted'

dotted line

'none','None','', or''

draw nothing

Alternatively a dash tuple of the following form can be provided:

(offset,onoffseq)

whereonoffseq is an even length tuple of on and off ink in points.

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

The line style.

set_linewidth(w)[source]#

Set the patch linewidth in points.

Parameters:
wfloat or None
set_ls(ls)[source]#

Alias forset_linestyle.

set_lw(w)[source]#

Alias forset_linewidth.

update_from(other)[source]#

Copy properties fromother toself.

zorder=1#

Examples usingmatplotlib.patches.Patch#

Multiple Axes animation

Multiple Axes animation

Inset locator demo

Inset locator demo

List of named colors

List of named colors

Looking glass

Looking glass

Path editor

Path editor

Pick event demo

Pick event demo

Polygon editor

Polygon editor

Trifinder Event Demo

Trifinder Event Demo

Viewlims

Viewlims

Clipping images with patches

Clipping images with patches

Many ways to plot images

Many ways to plot images

Curve with error band

Curve with error band

Stairs Demo

Stairs Demo

Anchored Artists

Anchored Artists

Identify whether artists intersect

Identify whether artists intersect

Custom projection

Custom projection

Building histograms using Rectangles and PolyCollections

Building histograms using Rectangles and PolyCollections

Matplotlib logo

Matplotlib logo

Packed-bubble chart

Packed-bubble chart

SVG filter pie

SVG filter pie

TickedStroke patheffect

TickedStroke patheffect

Draw flat objects in 3D plot

Draw flat objects in 3D plot

Bar of pie

Bar of pie

Arrow guide

Arrow guide

Reference for Matplotlib artists

Reference for Matplotlib artists

Compound path

Compound path

Dolphins

Dolphins

Mmh Donuts!!!

Mmh Donuts!!!

Ellipse with orientation arrow demo

Ellipse with orientation arrow demo

Ellipse Demo

Ellipse Demo

Drawing fancy boxes

Drawing fancy boxes

Hatch demo

Hatch demo

Hatch style reference

Hatch style reference

Circles, Wedges and Polygons

Circles, Wedges and Polygons

PathPatch object

PathPatch object

Bezier curve

Bezier curve

Anatomy of a figure

Anatomy of a figure

Firefox

Firefox

Integral as the area under a curve

Integral as the area under a curve

Hinton diagrams

Hinton diagrams

Ishikawa Diagram

Ishikawa Diagram

Radar chart (aka spider or star chart)

Radar chart (aka spider or star chart)

SkewT-logP diagram: using transforms and custom projections

SkewT-logP diagram: using transforms and custom projections

Boxplots

Boxplots

Plot a confidence ellipse of a two-dimensional dataset

Plot a confidence ellipse of a two-dimensional dataset

Create boxes from error bars using PatchCollection

Create boxes from error bars using PatchCollection

ggplot style sheet

ggplot style sheet

Grayscale style sheet

Grayscale style sheet

Petroff10 style sheet

Petroff10 style sheet

Style sheets reference

Style sheets reference

Axes box aspect

Axes box aspect

Controlling view limits using margins and sticky_edges

Controlling view limits using margins and sticky_edges

Axes zoom effect

Axes zoom effect

Scale invariant angle label

Scale invariant angle label

Angle annotations on bracket arrows

Angle annotations on bracket arrows

Annotate plots

Annotate plots

Compose custom legends

Compose custom legends

AnnotationBbox demo

AnnotationBbox demo

Using a text as a Path

Using a text as a Path

Text rotation mode

Text rotation mode

Placing text boxes

Placing text boxes

Text alignment

Text alignment

Artist tests

Artist tests

Ellipse with units

Ellipse with units

Menu

Menu

Path Tutorial

Path Tutorial

Transformations Tutorial

Transformations Tutorial

Legend guide

Legend guide

Specifying colors

Specifying colors

Annotations

Annotations

Text properties and layout

Text properties and layout
On this page