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 |
---|---|
a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array | |
unknown | |
bool | |
| bool or None |
| |
bool | |
Patch or (Path, Transform) or None | |
color | |
| color or None |
| color or None |
bool | |
str | |
{'/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*'} | |
bool | |
| |
object | |
| {'-', '--', '-.', ':', '', (offset, on-off-seq), ...} |
| float or None |
None or bool or float or callable | |
bool | |
(scale: float, length: float, randomness: float) | |
bool or None | |
str | |
bool | |
float |
Test whether the mouse event occurred in the patch.
Return whether the given point is inside the patch.
The point (x, y) to check, in target coordinates of self.get_transform()
. These are display coordinates for patches that are added to a figure or axes.
Add an additional margin on the patch in target coordinates of self.get_transform()
. See Path.contains_point
for further details.
The proper use of this method depends on the transform of the patch. Isolated patches do not have a transform. In this case, the patch creation coordinates and the point coordinates match. The following example 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 from the fact that this method is predominantly used to check if display coordinates (e.g. from mouse events) are within the patch. If you want to do the above check with data coordinates, you have to properly transform them first:
>>> center = 0, 0 >>> c = Circle(center, radius=1) >>> plt.gca().add_patch(c) >>> transformed_center = c.get_transform().transform(center) >>> c.contains_point(transformed_center) True
Return whether the given points are inside the patch.
The points to check, in target coordinates of self.get_transform()
. These are display coordinates for patches that are added to a figure or axes. Columns contain x and y values.
Add an additional margin on the patch in target coordinates of self.get_transform()
. See Path.contains_point
for further details.
The proper use of this method depends on the transform of the patch. See the notes on Patch.contains_point
.
Draw the Artist (and its children) using the given renderer.
This has no effect if the artist is not visible (Artist.get_visible
returns False).
RendererBase
subclass.
This method is overridden in the Artist subclasses.
Return whether the patch is filled.
Alias for get_antialiased
.
Return whether antialiasing is used for drawing.
Return the capstyle.
Alias for get_edgecolor
.
Return the edge color.
Return the face color.
Alias for get_facecolor
.
Return whether the patch is filled.
Return the hatching pattern.
Return the joinstyle.
Return the linestyle.
Return the line width in points.
Alias for get_linestyle
.
Alias for get_linewidth
.
Return the Transform
instance mapping 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 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 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 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 multiple properties at once.
Supported properties are
Property | Description |
---|---|
a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array | |
unknown | |
bool | |
bool or None | |
| |
bool | |
Patch or (Path, Transform) or None | |
color | |
color or None | |
color or None | |
bool | |
str | |
{'/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*'} | |
bool | |
| |
object | |
{'-', '--', '-.', ':', '', (offset, on-off-seq), ...} | |
float or None | |
None or bool or float or callable | |
bool | |
(scale: float, length: float, randomness: float) | |
bool or None | |
str | |
bool | |
float |
Alias for set_antialiased
.
Set the alpha value used for blending - not supported on all backends.
alpha must be within the 0-1 range, inclusive.
Set whether to use antialiased rendering.
Set both the edgecolor and the facecolor.
See also
Patch.set_facecolor
, Patch.set_edgecolor
For setting the edge or face color individually.
Alias for set_edgecolor
.
Set the patch edge color.
Set the patch face color.
Alias for set_facecolor
.
Set whether to fill the patch.
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.
Set the patch linestyle.
linestyle | description |
---|---|
| solid line |
| dashed line |
| dash-dotted line |
| dotted line |
| draw nothing |
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.
The line style.
Set the patch linewidth in points.
Alias for set_linestyle
.
Alias for set_linewidth
.
Copy properties from other to self.
matplotlib.patches.Patch
© 2012–2021 Matplotlib Development Team. All rights reserved.
Licensed under the Matplotlib License Agreement.
https://matplotlib.org/3.5.1/api/_as_gen/matplotlib.patches.Patch.html