Test whether *mouseevent* occurred on the line. An event is deemed to have occurred "on" the line if it is less than ``self.pickradius`` (default: 5 points) away from it. Use `~.Line2D.get_pickradius` or `~.Line2D.set_pickradius` to get or set the pick radi
(self, mouseevent)
| 428 | self.set_data(xdata, ydata) |
| 429 | |
| 430 | def contains(self, mouseevent): |
| 431 | """ |
| 432 | Test whether *mouseevent* occurred on the line. |
| 433 | |
| 434 | An event is deemed to have occurred "on" the line if it is less |
| 435 | than ``self.pickradius`` (default: 5 points) away from it. Use |
| 436 | `~.Line2D.get_pickradius` or `~.Line2D.set_pickradius` to get or set |
| 437 | the pick radius. |
| 438 | |
| 439 | Parameters |
| 440 | ---------- |
| 441 | mouseevent : `~matplotlib.backend_bases.MouseEvent` |
| 442 | |
| 443 | Returns |
| 444 | ------- |
| 445 | contains : bool |
| 446 | Whether any values are within the radius. |
| 447 | details : dict |
| 448 | A dictionary ``{'ind': pointlist}``, where *pointlist* is a |
| 449 | list of points of the line that are within the pickradius around |
| 450 | the event position. |
| 451 | |
| 452 | TODO: sort returned indices by distance |
| 453 | """ |
| 454 | if self._different_canvas(mouseevent): |
| 455 | return False, {} |
| 456 | |
| 457 | # Make sure we have data to plot |
| 458 | if self._invalidy or self._invalidx: |
| 459 | self.recache() |
| 460 | if len(self._xy) == 0: |
| 461 | return False, {} |
| 462 | |
| 463 | # Convert points to pixels |
| 464 | transformed_path = self._get_transformed_path() |
| 465 | path, affine = transformed_path.get_transformed_path_and_affine() |
| 466 | path = affine.transform_path(path) |
| 467 | xy = path.vertices |
| 468 | xt = xy[:, 0] |
| 469 | yt = xy[:, 1] |
| 470 | |
| 471 | # Convert pick radius from points to pixels |
| 472 | fig = self.get_figure(root=True) |
| 473 | if fig is None: |
| 474 | _log.warning('no figure set when check if mouse is on line') |
| 475 | pixels = self._pickradius |
| 476 | else: |
| 477 | pixels = fig.dpi / 72. * self._pickradius |
| 478 | |
| 479 | # The math involved in checking for containment (here and inside of |
| 480 | # segment_hits) assumes that it is OK to overflow, so temporarily set |
| 481 | # the error flags accordingly. |
| 482 | with np.errstate(all='ignore'): |
| 483 | # Check for collision |
| 484 | if self._linestyle in ['None', None]: |
| 485 | # If no line, return the nearby point(s) |
| 486 | ind, = np.nonzero( |
| 487 | (xt - mouseevent.x) ** 2 + (yt - mouseevent.y) ** 2 |
nothing calls this directly
no test coverage detected