Return whether the given point is inside the patch. Parameters ---------- point : (float, float) The point (x, y) to check, in target coordinates of ``.Patch.get_transform()``. These are display coordinates for patches that are ad
(self, point, radius=None)
| 181 | return inside, {} |
| 182 | |
| 183 | def contains_point(self, point, radius=None): |
| 184 | """ |
| 185 | Return whether the given point is inside the patch. |
| 186 | |
| 187 | Parameters |
| 188 | ---------- |
| 189 | point : (float, float) |
| 190 | The point (x, y) to check, in target coordinates of |
| 191 | ``.Patch.get_transform()``. These are display coordinates for patches |
| 192 | that are added to a figure or Axes. |
| 193 | radius : float, optional |
| 194 | Additional margin on the patch in target coordinates of |
| 195 | `.Patch.get_transform`. See `.Path.contains_point` for further |
| 196 | details. |
| 197 | |
| 198 | If `None`, the default value depends on the state of the object: |
| 199 | |
| 200 | - If `.Artist.get_picker` is a number, the default |
| 201 | is that value. This is so that picking works as expected. |
| 202 | - Otherwise if the edge color has a non-zero alpha, the default |
| 203 | is half of the linewidth. This is so that all the colored |
| 204 | pixels are "in" the patch. |
| 205 | - Finally, if the edge has 0 alpha, the default is 0. This is |
| 206 | so that patches without a stroked edge do not have points |
| 207 | outside of the filled region report as "in" due to an |
| 208 | invisible edge. |
| 209 | |
| 210 | Returns |
| 211 | ------- |
| 212 | bool |
| 213 | |
| 214 | Notes |
| 215 | ----- |
| 216 | The proper use of this method depends on the transform of the patch. |
| 217 | Isolated patches do not have a transform. In this case, the patch |
| 218 | creation coordinates and the point coordinates match. The following |
| 219 | example checks that the center of a circle is within the circle |
| 220 | |
| 221 | >>> center = 0, 0 |
| 222 | >>> c = Circle(center, radius=1) |
| 223 | >>> c.contains_point(center) |
| 224 | True |
| 225 | |
| 226 | The convention of checking against the transformed patch stems from |
| 227 | the fact that this method is predominantly used to check if display |
| 228 | coordinates (e.g. from mouse events) are within the patch. If you want |
| 229 | to do the above check with data coordinates, you have to properly |
| 230 | transform them first: |
| 231 | |
| 232 | >>> center = 0, 0 |
| 233 | >>> c = Circle(center, radius=3) |
| 234 | >>> plt.gca().add_patch(c) |
| 235 | >>> transformed_interior_point = c.get_data_transform().transform((0, 2)) |
| 236 | >>> c.contains_point(transformed_interior_point) |
| 237 | True |
| 238 | |
| 239 | """ |
| 240 | radius = self._process_radius(radius) |
no test coverage detected