Callback for mouse button release in zoom to rect mode.
(self, event)
| 3302 | self.draw_rubberband(event, x1, y1, x2, y2) |
| 3303 | |
| 3304 | def release_zoom(self, event): |
| 3305 | """Callback for mouse button release in zoom to rect mode.""" |
| 3306 | if self._zoom_info is None: |
| 3307 | return |
| 3308 | |
| 3309 | # We don't check the event button here, so that zooms can be cancelled |
| 3310 | # by (pressing and) releasing another mouse button. |
| 3311 | self.canvas.mpl_disconnect(self._zoom_info.cid) |
| 3312 | self.remove_rubberband() |
| 3313 | |
| 3314 | start_x, start_y = self._zoom_info.start_xy |
| 3315 | direction = "in" if self._zoom_info.button == 1 else "out" |
| 3316 | key = event.key |
| 3317 | # Force the key on colorbars to ignore the zoom-cancel on the |
| 3318 | # short-axis side |
| 3319 | if self._zoom_info.cbar == "horizontal": |
| 3320 | key = "x" |
| 3321 | elif self._zoom_info.cbar == "vertical": |
| 3322 | key = "y" |
| 3323 | # Ignore single clicks: 5 pixels is a threshold that allows the user to |
| 3324 | # "cancel" a zoom action by zooming by less than 5 pixels. |
| 3325 | if ((abs(event.x - start_x) < 5 and key != "y") or |
| 3326 | (abs(event.y - start_y) < 5 and key != "x")): |
| 3327 | self._cleanup_post_zoom() |
| 3328 | return |
| 3329 | |
| 3330 | for i, ax in enumerate(self._zoom_info.axes): |
| 3331 | # Detect whether this Axes is twinned with an earlier Axes in the |
| 3332 | # list of zoomed Axes, to avoid double zooming. |
| 3333 | twinx = any(ax.get_shared_x_axes().joined(ax, prev) |
| 3334 | for prev in self._zoom_info.axes[:i]) |
| 3335 | twiny = any(ax.get_shared_y_axes().joined(ax, prev) |
| 3336 | for prev in self._zoom_info.axes[:i]) |
| 3337 | ax._set_view_from_bbox( |
| 3338 | (start_x, start_y, event.x, event.y), |
| 3339 | direction, key, twinx, twiny) |
| 3340 | |
| 3341 | self._cleanup_post_zoom() |
| 3342 | self.push_current() |
| 3343 | |
| 3344 | def _cleanup_post_zoom(self): |
| 3345 | # We don't check the event button here, so that zooms can be cancelled |