MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / contains

Method contains

lib/matplotlib/image.py:640–656  ·  view source on GitHub ↗

Test whether the mouse event occurred within the image.

(self, mouseevent)

Source from the content-addressed store, hash-verified

638 self.stale = False
639
640 def contains(self, mouseevent):
641 """Test whether the mouse event occurred within the image."""
642 if (self._different_canvas(mouseevent)
643 # This doesn't work for figimage.
644 or not self.axes.contains(mouseevent)[0]):
645 return False, {}
646 # TODO: make sure this is consistent with patch and patch
647 # collection on nonlinear transformed coordinates.
648 # TODO: consider returning image coordinates (shouldn't
649 # be too difficult given that the image is rectilinear
650 trans = self.get_transform().inverted()
651 x, y = trans.transform([mouseevent.x, mouseevent.y])
652 xmin, xmax, ymin, ymax = self.get_extent()
653 # This checks xmin <= x <= xmax *or* xmax <= x <= xmin.
654 inside = (x is not None and (x - xmin) * (x - xmax) <= 0
655 and y is not None and (y - ymin) * (y - ymax) <= 0)
656 return inside, {}
657
658 def write_png(self, fname):
659 """Write the image to png file *fname*."""

Callers

nothing calls this directly

Calls 6

_different_canvasMethod · 0.80
containsMethod · 0.45
invertedMethod · 0.45
get_transformMethod · 0.45
transformMethod · 0.45
get_extentMethod · 0.45

Tested by

no test coverage detected