matplotlib 3.5.1

NotesParametersReturnsBackRef
contains_point(self, point, radius=None)

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

Parameters

point : (float, float)

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.

radius : float, optional

Add an additional margin on the patch in target coordinates of self.get_transform() . See .Path.contains_point for further details.

Returns

bool

Return whether the given point is inside the patch.

Examples

See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

matplotlib.patches.Patch.contains_points

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /matplotlib/patches.py#171
type: <class 'function'>
Commit: