matplotlibslidermatplotlib-widget

Pass arguments to slider update?


UPDATE: I learned the basics of matplotlib so now I realize my previous question was out of place, but now I've run into a new problem. Let's say I have a slider that is updated with

def update_execution(val):
    executionStep = int(executionSlider.val)
    #Do stuff

slider.on_changed(update_execution)

Is there a way I can modify this so that I can pass other arguments to update_execution()? i.e something like this:

def update_execution(val, globalparam):
    executionStep = int(executionSlider.val)
    globalparam = 'foo'
    #Do stuff

slider.on_changed(update_execution(globalparam))`

Thanks :)


Solution

  • Definitely not a best practice, although in small contexts it doesn't really matter, but I figured out the best way to solve this is is by declaring the variable you want to modify as a global var

    def update_execution(val):
        executionStep = int(executionSlider.val)
        global globalparam
        globalparam = 'foo'
        #Do stuff 
    slider.on_changed(update_execution)