0

I'm trying to make use of Interact in a Jupyter Notebook. A bit down on that page, it's stated that

On occasion, you may notice interact output flickering and jumping, causing the notebook scroll position to change as the output is updated. The interactive control has a layout, so we can set its height to an appropriate value (currently chosen manually) so that it will not change size as it is updated.

And I'm experiencing exactly that problem when I'm trying to replicate the example.

The following snippet...

%matplotlib inline
from ipywidgets import interactive
import matplotlib.pyplot as plt
import numpy as np

def f(m, b):
    plt.figure(2)
    x = np.linspace(-10, 10, num=1000)
    plt.plot(x, m * x + b)
    plt.ylim(-5, 5)
    plt.show()

interactive_plot = interactive(f, m=(-2.0, 2.0), b=(-3, 3, 0.5))
output = interactive_plot.children[-1]
output.layout.height = '350px'
interactive_plot

... should produce this output:

enter image description here

But I'm only getting this:

enter image description here

To be precise, the sliders do pop up for half a second, but seem to be overwritten by the graph. I'm guessing that this is exactly the problem they are adressing. So I thought I could remedy the problem using different values than 350 in output.layout.height = '350px', but with absolutley no success so far. I've tried 100, 200, 250, 300, 750 and 1400.

So could there be something else causing the problems?

Thank you for any suggestions!

vestland
  • 55,229
  • 37
  • 187
  • 305

1 Answers1

1

I just checked that the solution proposed here:

Jupyter Notebook: interactive plot with widgets

works with recent classic Jupyter.

To avoid flickering you could switch to using https://github.com/AaronWatters/jp_doodle -- look at the examples under "Features" named interactive*. The jp_doodle dual_canvas has a context manager which suppresses intermediate updates.

Aaron Watters
  • 2,784
  • 3
  • 23
  • 37