Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d03c337

Browse files
authored
Merge pull request #17482 from anntzer/rsx
Shorten RectangleSelector._release.
2 parents 35808ec + 81a9396 commit d03c337

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

lib/matplotlib/widgets.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,30 +2068,21 @@ def _release(self, event):
20682068
xy2 = self.ax.transData.transform([x2, y2])
20692069
self.eventrelease.x, self.eventrelease.y = xy2
20702070

2071+
# calculate dimensions of box or line
20712072
if self.spancoords == 'data':
2072-
xmin, ymin = self.eventpress.xdata, self.eventpress.ydata
2073-
xmax, ymax = self.eventrelease.xdata, self.eventrelease.ydata
2074-
# calculate dimensions of box or line get values in the right order
2073+
spanx = abs(self.eventpress.xdata - self.eventrelease.xdata)
2074+
spany = abs(self.eventpress.ydata - self.eventrelease.ydata)
20752075
elif self.spancoords == 'pixels':
2076-
xmin, ymin = self.eventpress.x, self.eventpress.y
2077-
xmax, ymax = self.eventrelease.x, self.eventrelease.y
2076+
spanx = abs(self.eventpress.x - self.eventrelease.x)
2077+
spany = abs(self.eventpress.y - self.eventrelease.y)
20782078
else:
20792079
cbook._check_in_list(['data', 'pixels'],
20802080
spancoords=self.spancoords)
2081-
2082-
if xmin > xmax:
2083-
xmin, xmax = xmax, xmin
2084-
if ymin > ymax:
2085-
ymin, ymax = ymax, ymin
2086-
2087-
spanx = xmax - xmin
2088-
spany = ymax - ymin
2089-
xproblems = self.minspanx is not None and spanx < self.minspanx
2090-
yproblems = self.minspany is not None and spany < self.minspany
2091-
20922081
# check if drawn distance (if it exists) is not too small in
20932082
# either x or y-direction
2094-
if self.drawtype != 'none' and (xproblems or yproblems):
2083+
if (self.drawtype != 'none'
2084+
and (self.minspanx is not None and spanx < self.minspanx
2085+
or self.minspany is not None and spany < self.minspany)):
20952086
for artist in self.artists:
20962087
artist.set_visible(False)
20972088
self.update()

0 commit comments

Comments
 (0)