@@ -154,10 +154,47 @@ def contains(self, mouseevent, radius=None):
154
154
155
155
def contains_point (self , point , radius = None ):
156
156
"""
157
- Returns ``True`` if the given *point* is inside the path
158
- (transformed with its transform attribute).
157
+ Return whether the given point is inside the patch.
158
+
159
+ Parameters
160
+ ----------
161
+ point : (float, float)
162
+ The point (x, y) to check in target coordinates of
163
+ ``self.get_transform()``. For patches added to a figure or axes,
164
+ these are display coordinates.
165
+ radius : float, optional
166
+ Adds an additional margin on the patch in coordinates of transform.
167
+ target. See `.Path.contains_point` for further details.
168
+
169
+ Returns
170
+ -------
171
+ bool
172
+
173
+ Notes
174
+ -----
175
+ The proper use of this method depends on the transform of the patch.
176
+ Isolated patches do not have a transform. In this, the patch creation
177
+ coordinates and the point coordinates match. The follow checks that
178
+ the center of a circle is within the circle
179
+
180
+ >>> center = 0, 0
181
+ >>> c = Circle(center, radius=1)
182
+ >>> c.contains_point(center)
183
+ True
184
+
185
+ The convention of checking against the transformed patch stems from
186
+ the fact that this method is predominantly used to check if display
187
+ coordinates (e.g. from mouse events) are within the patch. If you want
188
+ to do the above check with data coordinates, you have to properly
189
+ transform them first:
190
+
191
+ >>> center = 0, 0
192
+ >>> c = Circle(center, radius=1)
193
+ >>> plt.gca().add_patch(c)
194
+ >>> transformed_center = c.get_transform().transform(center)
195
+ >>> c.contains_point(transformed_center)
196
+ True
159
197
160
- *radius* allows the path to be made slightly larger or smaller.
161
198
"""
162
199
radius = self ._process_radius (radius )
163
200
return self .get_path ().contains_point (point ,
@@ -166,12 +203,26 @@ def contains_point(self, point, radius=None):
166
203
167
204
def contains_points (self , points , radius = None ):
168
205
"""
169
- Returns a bool array which is ``True`` if the (closed) path
170
- contains the corresponding point.
171
- (transformed with its transform attribute).
206
+ Return whether the given points are inside the patch.
172
207
173
- *points* must be Nx2 array.
174
- *radius* allows the path to be made slightly larger or smaller.
208
+ Parameters
209
+ ----------
210
+ points : (N, 2) array
211
+ The points to check in target coordinates of
212
+ ``self.get_transform()``. For patches added to a figure or axes,
213
+ these are display coordinates. Columns contain x and y values.
214
+ radius : float, optional
215
+ Adds an additional margin on the patch in coordinates of transform.
216
+ target. See `.Path.contains_points` for further details.
217
+
218
+ Returns
219
+ -------
220
+ length-N bool array
221
+
222
+ Notes
223
+ -----
224
+ The proper use of this method depends on the transform of the patch.
225
+ See the notes on `.Patch.contains_point`.
175
226
"""
176
227
radius = self ._process_radius (radius )
177
228
return self .get_path ().contains_points (points ,
0 commit comments