Skip to content

Fixes zoom rubberband display on macOS w/ wxagg and multiple subplots #9005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 7, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1614,10 +1614,12 @@ def press(self, event):
if not self.retinaFix:
self.wxoverlay = wx.Overlay()
else:
self.savedRetinaImage = self.canvas.copy_from_bbox(
self.canvas.figure.gca().bbox)
self.zoomStartX = event.xdata
self.zoomStartY = event.ydata
if event.inaxes is not None:
self.savedRetinaImage = self.canvas.copy_from_bbox(
event.inaxes.bbox)
self.zoomStartX = event.xdata
self.zoomStartY = event.ydata
self.zoomAxes = event.inaxes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this a private member (precede it with an underscore)? Also, we should probably clear it when the rubber-banding is finished so we don't hang onto the axes reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats easy enough to do. However, making it private makes it inconsistent with the zoomStart variables, which is why I left it as is. I could also change those, but wasn't sure if they were public for a reason. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No clue if they were public for any particular reason except legacy. We should keep those two as-is, but the zoomAxes should be private under the philosophy that it is easier to make something public later, than to make it private. If it doesn't need to be public, then default to private for anything new.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case I think it makes more senses to be consistent with the existing group of names on the 'when-in-rome' principle.

Lets leave everything as 'public' for now.


def release(self, event):
if self._active == 'ZOOM':
Expand All @@ -1631,6 +1633,8 @@ def release(self, event):
if self.prevZoomRect:
self.prevZoomRect.pop(0).remove()
self.prevZoomRect = None
if self.zoomAxes:
self.zoomAxes = None

def draw_rubberband(self, event, x0, y0, x1, y1):
if self.retinaFix: # On Macs, use the following code
Expand All @@ -1643,10 +1647,10 @@ def draw_rubberband(self, event, x0, y0, x1, y1):
Y0, Y1 = self.zoomStartY, event.ydata
lineX = (X0, X0, X1, X1, X0)
lineY = (Y0, Y1, Y1, Y0, Y0)
self.prevZoomRect = self.canvas.figure.gca().plot(
self.prevZoomRect = self.zoomAxes.plot(
lineX, lineY, '-', color=rubberBandColor)
self.canvas.figure.gca().draw_artist(self.prevZoomRect[0])
self.canvas.blit(self.canvas.figure.gca().bbox)
self.zoomAxes.draw_artist(self.prevZoomRect[0])
self.canvas.blit(self.zoomAxes.bbox)
return

# Use an Overlay to draw a rubberband-like bounding box.
Expand Down