Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf99b6ee

Browse files
authored
Merge pull request#25558 from anntzer/ic
Simplify outdated Image.contains check.
2 parents1a37213 +6a30406 commitf99b6ee

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

‎lib/matplotlib/image.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -654,14 +654,9 @@ def draw(self, renderer, *args, **kwargs):
654654

655655
defcontains(self,mouseevent):
656656
"""Test whether the mouse event occurred within the image."""
657-
ifself._different_canvas(mouseevent):
658-
returnFalse, {}
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-
ifself.axesisnotmouseevent.inaxes:
657+
if (self._different_canvas(mouseevent)
658+
# This doesn't work for figimage.
659+
ornotself.axes.contains(mouseevent)[0]):
665660
returnFalse, {}
666661
# TODO: make sure this is consistent with patch and patch
667662
# collection on nonlinear transformed coordinates.
@@ -670,16 +665,9 @@ def contains(self, mouseevent):
670665
trans=self.get_transform().inverted()
671666
x,y=trans.transform([mouseevent.x,mouseevent.y])
672667
xmin,xmax,ymin,ymax=self.get_extent()
673-
ifxmin>xmax:
674-
xmin,xmax=xmax,xmin
675-
ifymin>ymax:
676-
ymin,ymax=ymax,ymin
677-
678-
ifxisnotNoneandyisnotNone:
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= (xisnotNoneand (x-xmin)* (x-xmax)<=0
670+
andyisnotNoneand (y-ymin)* (y-ymax)<=0)
683671
returninside, {}
684672

685673
defwrite_png(self,fname):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp