Skip to content

Sliders unresponsive when created inside a function #3105

@lebigot

Description

@lebigot

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy