You are reading an old version of the documentation (v3.1.3). For the latest version see
Version 3.1.3
Fork me on GitHub

Table of Contents


class matplotlib.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: matplotlib.artist.Artist

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

If any of edgecolor, facecolor, linewidth, or antialiased are None, 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
alpha float or None
animated bool
antialiased or aa unknown
capstyle {'butt', 'round', 'projecting'}
clip_box Bbox
clip_on bool
clip_path [(Path, Transform) | Patch | None]
color color
contains callable
edgecolor or ec color or None or 'auto'
facecolor or fc color or None
figure Figure
fill bool
gid str
hatch {'/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}
in_layout bool
joinstyle {'miter', 'round', 'bevel'}
label object
linestyle or ls {'-', '--', '-.', ':', '', (offset, on-off-seq), ...}
linewidth or lw float or None
path_effects AbstractPathEffect
picker None or bool or float or callable
rasterized bool or None
sketch_params (scale: float, length: float, randomness: float)
snap bool or None
transform Transform
url str
visible bool
zorder float
contains(self, mouseevent, radius=None)[source]

Test whether the mouse event occurred in the patch.

(bool, empty dict)
contains_point(self, point, radius=None)[source]

Returns True if the given point is inside the path (transformed with its transform attribute).

radius allows the path to be made slightly larger or smaller.

contains_points(self, points, radius=None)[source]

Returns a bool array which is True if the (closed) path contains the corresponding point. (transformed with its transform attribute).

points must be Nx2 array. radius allows the path to be made slightly larger or smaller.

draw(self, renderer)[source]

Draw the Patch to the given renderer.


return whether fill is set


Alias for get_antialiased.


Returns True if the Patch is to be drawn with antialiasing.


Return the current capstyle


Return the Transform instance which maps data coordinates to physical coordinates.


Alias for get_edgecolor.


Return the edge color of the Patch.


Return a Bbox object defining the axis-aligned extents of the Patch.


Return the face color of the Patch.


Alias for get_facecolor.


return whether fill is set


Return the current hatching pattern


Return the current joinstyle


Return the linestyle.


Return the line width in points.


Alias for get_linestyle.


Alias for get_linewidth.


Return the Transform instance which takes patch coordinates to data coordinates.

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


Return the path of this patch


Return the Transform applied to the Patch.


Return a copy of the vertices used in this patch

If the patch contains Bezier curves, the curves will be interpolated by line segments. To access the curves as curves, use get_path().

get_window_extent(self, renderer=None)[source]

Get the axes 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 bounding box at 0, 0.

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

set_aa(self, aa)

Alias for set_antialiased.

set_alpha(self, alpha)[source]

Set the alpha transparency of the patch.

alpha : float or None
set_antialiased(self, aa)[source]

Set whether to use antialiased rendering.

b : bool or None
set_capstyle(self, s)[source]

Set the patch capstyle

s : {'butt', 'round', 'projecting'}
set_color(self, c)[source]

Set both the edgecolor and the facecolor.

c : color

See also

Patch.set_facecolor, Patch.set_edgecolor
For setting the edge or face color individually.
set_ec(self, color)

Alias for set_edgecolor.

set_edgecolor(self, color)[source]

Set the patch edge color.

color : color or None or 'auto'
set_facecolor(self, color)[source]

Set the patch face color.

color : color or None
set_fc(self, color)

Alias for set_facecolor.

set_fill(self, b)[source]

Set whether to fill the patch.

b : bool
set_hatch(self, hatch)[source]

Set the hatching pattern

hatch can be one of:

/   - diagonal hatching
\   - back diagonal
|   - vertical
-   - horizontal
+   - crossed
x   - crossed diagonal
o   - small circle
O   - large circle
.   - dots
*   - stars

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

Hatching is supported in the PostScript, PDF, SVG and Agg backends only.

hatch : {'/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}
set_joinstyle(self, s)[source]

Set the patch joinstyle

s : {'miter', 'round', 'bevel'}
set_linestyle(self, 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

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

(offset, onoffseq),

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

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

The line style.

set_linewidth(self, w)[source]

Set the patch linewidth in points.

w : float or None
set_ls(self, ls)

Alias for set_linestyle.

set_lw(self, w)

Alias for set_linewidth.

update_from(self, other)[source]

Updates this Patch from the properties of other.

validCap = ('butt', 'round', 'projecting')
validJoin = ('miter', 'round', 'bevel')
zorder = 1

Examples using matplotlib.patches.Patch