Ask Your Question

sage interactive disable auto update?

asked 2019-04-05 08:09:31 -0600

msage gravatar image

i have a sheet with interactive sliders which generates plots. when I alter a value on a slider, the plot is executed not only at the destination value, but also on many steps between starting point and destination. As the plot takes some time, it is very slow to get the result. Is there a possibility to deactivate autoupdate, and for example make a Button for executing the script with the new values?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2019-04-07 19:48:26 -0600

Juanjo gravatar image

updated 2019-11-23 19:07:36 -0600

You can add auto_update=False as an argument to the function defining the interact. For example:

def _(a=slider(0,5,step_size=0.2,default=3),
    show(plot(sin(a*x)+cos(b*x), (x,0,4*pi), color=color))

The interact is only updated when you press the button below the interact controls. See this SageMath Cell.

At least in a Jupyter notebook, you can also use an alternative syntax:

def _(a=slider(0,5,step_size=0.2,default=3),
    show(plot(sin(a*x)+cos(b*x), (x,0,4*pi), color=color))

The button text can be customized. If you prefer, say, "Redraw" instead of the default text, just modify the first line in the preceding snippet as follows:

@interact.options(manual=True, manual_name="Redraw")

Edit (24th Nov. 2019): In a SageMath Cell, one can replace auto_update=False by, for example, auto=UpdateButton(text="Redraw"). The text written in the button will be Redraw. The button can be referred by auto when specifying the layout, if any. For example,

@interact(layout=dict(top=[["a","b"],["color"]], bottom=[["auto"]]))
def _(a=slider(0,5, step_size=0.2, default=3),
      b=slider(0,5, step_size=0.2, default=1),
      color=selector(["red","green","blue"], label="Color", 
                      default="green", buttons=True),
    show(plot(sin(a*x)+cos(b*x), (x,0,4*pi), color=color))

See this SageMath cell.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2019-04-05 08:09:31 -0600

Seen: 239 times

Last updated: Nov 23 '19