Closed
Description
When a Slider is created inside a function, it is typically non-responsive (does not react to the mouse):
from matplotlib import pyplot
from matplotlib.widgets import Slider
sliders = []
def open_fig_with_slider():
pyplot.figure()
slider = Slider(pyplot.axes([0.25, 0.1, 0.65, 0.03]),
'Slider', 0, 1, valinit=0.5)
# sliders.append(slider)
open_fig_with_slider()
pyplot.show() # The slider is unresponsive unless append above is un-commented
The problem appears to be fixed by keeping a reference to the slider. The closest thing I've found in the documentation is that a canvas only keeps weak references to its callbacks (http://matplotlib.org/users/event_handling.html). However, the connection with sliders is not so obvious—if there is any.
If I'm not mistaken, this behavior is not documented, so it would be nice to add it to the documentation, if it is normal.