Ask Your Question
1

sage interactive disable auto update?

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

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
3

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

Juanjo gravatar image

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

@interact
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"),
      auto_update=False):
    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:

@interact.options(manual=True)
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")):
    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 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

2 followers

Stats

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

Seen: 65 times

Last updated: Apr 07