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

Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Clear the labels when resizing but update size
  • Loading branch information
blink1073 committed Nov 14, 2016
commit 2f6eb99d0cade736c5bbf9144a3a7f87fa09facb
19 changes: 12 additions & 7 deletions lib/matplotlib/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2680,15 +2680,10 @@ def __init__(self, ax, on_select=None, overlay_props=None,
extent=(x0, x1, y0, y1), aspect=self.ax.get_aspect())
props.update(overlay_props or {})

extents = self.ax.get_window_extent().extents
self._offsetx = extents[0]
self._offsety = extents[1]
self._shape = (int(extents[3] - extents[1]),
int(extents[2] - extents[0]))
self._overlay = np.zeros(self._shape, dtype='uint8')
self._resize(None)
self._overlay_plot = self.ax.imshow(self._overlay, **props)

self.artists = [self._cursor, self._overlay_plot]
self.connect_event('resize_event', self._resize)

# These must be called last
self.label = 1
Expand Down Expand Up @@ -2758,6 +2753,16 @@ def _onmove(self, event):
self.update()
self.onselect(event.xdata, event.ydata)

def _resize(self, event):
extents = self.ax.get_window_extent().extents
self._offsetx = extents[0]
self._offsety = extents[1]
self._shape = (int(extents[3] - extents[1]),
int(extents[2] - extents[0]))
self._overlay = np.zeros(self._shape, dtype='uint8')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You may be able to use _image.resample in the same way that imshow eventually does if you want take a stab at preserving the overlay.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That uses a lot of private APIs, I'd prefer to keep this simple. I added a note about the clearing behavior in the docs.

if self._overlay_plot:
self._overlay_plot.set_data(self._overlay)

def _release(self, event):
pass

Expand Down