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

Skip to content

Commit 81a9396

Browse files
committed
Shorten RectangleSelector._release.
Just get rid of plenty of temporary variables (xmin, xmax, ymin, ymax, xproblems, yproblems) which obscure the actual (simple!) computation that matters.
1 parent 969513e commit 81a9396

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
@@ -2094,30 +2094,21 @@ def _release(self, event):
20942094
xy2 = self.ax.transData.transform([x2, y2])
20952095
self.eventrelease.x, self.eventrelease.y = xy2
20962096

2097+
# calculate dimensions of box or line
20972098
if self.spancoords == 'data':
2098-
xmin, ymin = self.eventpress.xdata, self.eventpress.ydata
2099-
xmax, ymax = self.eventrelease.xdata, self.eventrelease.ydata
2100-
# calculate dimensions of box or line get values in the right order
2099+
spanx = abs(self.eventpress.xdata - self.eventrelease.xdata)
2100+
spany = abs(self.eventpress.ydata - self.eventrelease.ydata)
21012101
elif self.spancoords == 'pixels':
2102-
xmin, ymin = self.eventpress.x, self.eventpress.y
2103-
xmax, ymax = self.eventrelease.x, self.eventrelease.y
2102+
spanx = abs(self.eventpress.x - self.eventrelease.x)
2103+
spany = abs(self.eventpress.y - self.eventrelease.y)
21042104
else:
21052105
cbook._check_in_list(['data', 'pixels'],
21062106
spancoords=self.spancoords)
2107-
2108-
if xmin > xmax:
2109-
xmin, xmax = xmax, xmin
2110-
if ymin > ymax:
2111-
ymin, ymax = ymax, ymin
2112-
2113-
spanx = xmax - xmin
2114-
spany = ymax - ymin
2115-
xproblems = self.minspanx is not None and spanx < self.minspanx
2116-
yproblems = self.minspany is not None and spany < self.minspany
2117-
21182107
# check if drawn distance (if it exists) is not too small in
21192108
# either x or y-direction
2120-
if self.drawtype != 'none' and (xproblems or yproblems):
2109+
if (self.drawtype != 'none'
2110+
and (self.minspanx is not None and spanx < self.minspanx
2111+
or self.minspany is not None and spany < self.minspany)):
21212112
for artist in self.artists:
21222113
artist.set_visible(False)
21232114
self.update()

0 commit comments

Comments
 (0)