Unless the user interacts with widget, ipywidgets doesn't show the plot. How can I solve this? Perhaps if I could update a slider value using some code, the plot would show. I think this issue only arises when the Layout configuration method is used.
import numpy as np
from matplotlib import pyplot as plt
from ipywidgets import interactive, fixed, FloatSlider, HBox, Layout
from IPython.display import display
ts = np.arange(0.0, 5.0, 0.01)
def plotFunc(omega):
    plt.plot(ts, np.cos(omega*ts))
w = interactive(plotFunc, omega = FloatSlider(min = 0, max = 12, step = 1, value = 6, orientation = 'vertical'))
box_layout = Layout(display = 'flex', flex_flow = 'row', justify_content = 'center', align_items = 'center')
display(HBox([w.children[-1], w.children[0]], layout = box_layout))
To enable the inline backend for usage with the IPython Notebook:
%matplotlib inline
and this at the end of your code:
w.update()
%matplotlib inline commands IPython Documentation, 
also IPython.display.set_matplotlib_formats and IPython.display.set_matplotlib_close for more information on changing additional behaviors of the inline backend.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With