You are reading documentation for the unreleased version of Matplotlib. Try searching for the released version of this page instead?
Applications are open for the 2018 John Hunter Matplotlib Summer Fellowship. Apply now!
Version 2.2.2.post1176+gec66f365d
matplotlib
Fork me on GitHub

Table Of Contents

matplotlib.patches.Patch

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]

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 bool or None
capstyle [‘butt’ | ‘round’ | ‘projecting’]
clip_box a Bbox instance
clip_on bool
clip_path [(Path, Transform) | Patch | None]
color matplotlib color spec
contains a callable function
edgecolor mpl color spec, None, ‘none’, or ‘auto’
facecolor mpl color spec, or None for default, or ‘none’ for no color
figure a Figure instance
fill bool
gid an id string
hatch [‘/’ | ‘' | ‘|’ | ‘-‘ | ‘+’ | ‘x’ | ‘o’ | ‘O’ | ‘.’ | ‘*’]
joinstyle [‘miter’ | ‘round’ | ‘bevel’]
label object
linestyle [‘solid’ | ‘dashed’, ‘dashdot’, ‘dotted’ | (offset, on-off-dash-seq) | '-' | '--' | '-.' | ':' | 'None' | ' ' | '']
linewidth float or None for default
path_effects AbstractPathEffect
picker [None | bool | float | callable]
rasterized bool or None
sketch_params (scale: float, length: float, randomness: float)
snap bool or None
transform Transform
url a url string
visible bool
zorder float
contains(mouseevent, radius=None)[source]

Test whether the mouse event occurred in the patch.

Returns T/F, {}

contains_point(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(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(renderer)[source]

Draw the Patch to the given renderer.

fill

return whether fill is set

get_aa(*args, **kwargs)

alias for get_antialiased

get_antialiased()[source]

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

get_capstyle()[source]

Return the current capstyle

get_data_transform()[source]

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

get_ec(*args, **kwargs)

alias for get_edgecolor

get_edgecolor()[source]

Return the edge color of the Patch.

get_extents()[source]

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

get_facecolor()[source]

Return the face color of the Patch.

get_fc(*args, **kwargs)

alias for get_facecolor

get_fill()[source]

return whether fill is set

get_hatch()[source]

Return the current hatching pattern

get_joinstyle()[source]

Return the current joinstyle

get_linestyle()[source]

Return the linestyle. Will be one of [‘solid’ | ‘dashed’ | ‘dashdot’ | ‘dotted’]

get_linewidth()[source]

Return the line width in points.

get_ls(*args, **kwargs)

alias for get_linestyle

get_lw(*args, **kwargs)

alias for get_linewidth

get_patch_transform()[source]

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.

get_path()[source]

Return the path of this patch

get_transform()[source]

Return the Transform applied to the Patch.

get_verts()[source]

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(renderer=None)[source]

Get the axes bounding box in display space. 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(*args, **kwargs)

alias for set_antialiased

set_alpha(alpha)[source]

Set the alpha transparency of the patch.

ACCEPTS: float or None

set_antialiased(aa)[source]

Set whether to use antialiased rendering.

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

Set the patch capstyle

ACCEPTS: [‘butt’ | ‘round’ | ‘projecting’]

set_color(c)[source]

Set both the edgecolor and the facecolor.

ACCEPTS: matplotlib color spec

See also

set_facecolor(), set_edgecolor()
For setting the edge or face color individually.
set_ec(*args, **kwargs)

alias for set_edgecolor

set_edgecolor(color)[source]

Set the patch edge color

ACCEPTS: mpl color spec, None, ‘none’, or ‘auto’

set_facecolor(color)[source]

Set the patch face color

ACCEPTS: mpl color spec, or None for default, or ‘none’ for no color

set_fc(*args, **kwargs)

alias for set_facecolor

set_fill(b)[source]

Set whether to fill the patch.

Parameters:
b : bool
set_hatch(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.

ACCEPTS: [‘/’ | ‘' | ‘|’ | ‘-‘ | ‘+’ | ‘x’ | ‘o’ | ‘O’ | ‘.’ | ‘*’]

set_joinstyle(s)[source]

Set the patch joinstyle

ACCEPTS: [‘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

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.

ACCEPTS: [‘solid’ | ‘dashed’, ‘dashdot’, ‘dotted’ |
(offset, on-off-dash-seq) | '-' | '--' | '-.' | ':' | 'None' | ' ' | '']
Parameters:
ls : { ‘-‘, ‘–’, ‘-.’, ‘:’} and more see description

The line style.

set_linewidth(w)[source]

Set the patch linewidth in points

ACCEPTS: float or None for default

set_ls(*args, **kwargs)

alias for set_linestyle

set_lw(*args, **kwargs)

alias for set_linewidth

update_from(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