When I run this example and create a rectangular selection if I zoom or move the plot window around the selection disappears until I deselect the move or zoom tool and click on the plot window again.
I am using %matplotlib tkinter in an IPython notebook.
I've attempted hooking into the limit changes that occur when the window is zoomed and setting the rectangular selection to visible:
def persist_rect(newlims):
rs = toggle_selector.RS
print(rs.visible)
rs.set_visible(True)
rs.update()
current_ax.callbacks.connect('xlim_changed', persist_rect)
current_ax.callbacks.connect('ylim_changed', persist_rect)
But this doesn't seem to do anything. It doesn't even appear that toggle_selector.RS.visible is ever set to false.
I've also been looking at the source for RectangleSelector, but I haven't seen anything enlightening there.
I've also discovered that I have this issue when I modify the extent of the selected region using RectangleSelector.extents = new_extents. When .extents is modified, for example with a slider widget, the selected region disappears until I click on the plot again.
All of these problems problems go away if the RectangleSelector is initialized with useblit=False as @ImportanceOfBeingErnest suggests, but, as they say, it's not a very performant solution.