简体   繁体   中英

Rendering Delay with Interact Widgets in IPython Notebook

When using the Interactive Widgets in IPython Notebook, in particular FloatSliderWidget, is there a way to delay the rendering of the final result?

I'm using the widgets and basemap to display map data and the attempts to render at each step (when sliding the slider - controlling image overlay alpha) is very slow.

Can I set some flag etc. that delays final rendering? Or add a button to display the image when I've set all my sliders?

Many thanks for any help.

Cheers, J.

There is an interact_manual function which works like interact but with a 'Run' button instead of automatic updating. Docs . I think this is new in IPython 3.

For throttling widgets more generally, all widgets should have a .msg_throttle attribute. This is how many updates can be 'in the pipe' at once. The default is 3, so when you're dragging your slider, it queues three values to get results. Setting it down to 1 should make it more responsive for slow functions - it won't send another value until the previous execution finishes. For quicker functions, a lower value would make the output change less smoothly.

Update for 2019

There is now the option continuous_update=False , which restricts executions from sliders to mouse release events only.

( https://minrk-ipywidgets.readthedocs.io/en/latest/examples/Using%20Interact.html )

In action it looks like this:

from ipywidgets import *
import numpy as np
import matplotlib.pyplot as plt
t= np.arange(0,1,0.01)
def pltsin(f):
    plt.plot(t,np.sin(2*np.pi*t*f))
    plt.show()
interact(pltsin,f=FloatSlider(min=1, max=23, step=1,continuous_update=False))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM