@@ -654,14 +654,9 @@ def draw(self, renderer, *args, **kwargs):
654
654
655
655
def contains (self , mouseevent ):
656
656
"""Test whether the mouse event occurred within the image."""
657
- if self ._different_canvas (mouseevent ):
658
- return False , {}
659
- # 1) This doesn't work for figimage; but figimage also needs a fix
660
- # below (as the check cannot use x/ydata and extents).
661
- # 2) As long as the check below uses x/ydata, we need to test axes
662
- # identity instead of `self.axes.contains(event)` because even if
663
- # axes overlap, x/ydata is only valid for event.inaxes anyways.
664
- if self .axes is not mouseevent .inaxes :
657
+ if (self ._different_canvas (mouseevent )
658
+ # This doesn't work for figimage.
659
+ or not self .axes .contains (mouseevent )[0 ]):
665
660
return False , {}
666
661
# TODO: make sure this is consistent with patch and patch
667
662
# collection on nonlinear transformed coordinates.
@@ -670,16 +665,9 @@ def contains(self, mouseevent):
670
665
trans = self .get_transform ().inverted ()
671
666
x , y = trans .transform ([mouseevent .x , mouseevent .y ])
672
667
xmin , xmax , ymin , ymax = self .get_extent ()
673
- if xmin > xmax :
674
- xmin , xmax = xmax , xmin
675
- if ymin > ymax :
676
- ymin , ymax = ymax , ymin
677
-
678
- if x is not None and y is not None :
679
- inside = (xmin <= x <= xmax ) and (ymin <= y <= ymax )
680
- else :
681
- inside = False
682
-
668
+ # This checks xmin <= x <= xmax *or* xmax <= x <= xmin.
669
+ inside = (x is not None and (x - xmin ) * (x - xmax ) <= 0
670
+ and y is not None and (y - ymin ) * (y - ymax ) <= 0 )
683
671
return inside , {}
684
672
685
673
def write_png (self , fname ):
0 commit comments