Best way to update a stack plot via sliders

I try to find a way to update a stack plot via sliders. Iam using Jupyterlab. There would be the way to do that with sliders from ipywidgets or the slider function of the plotly layout argument. First I tried to define a update function in which always iplot(fig) with updated data is called. But this is very ugly because the graph is alwyas new rendered, rescaling and it does not look like the graph is really updated(what it actually is true because its always a new graph). The slider keyword of iplot in offline mode does not have an extend or append mode via fileopt, so this is also no solution. The sliders of ipywidgets somehow do not change my graph:

from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets

N = 1000
x = np.linspace(1, 100, N)
y = np.arange(0,1000)
y2 = np.arange(1000,2000)
y3 = np.random.randn(N)+9

df = pd.DataFrame({'x': x, 'y': y, 'y2':y2, 'y3':y3})

#for step in resolution(1000):
data = [
        x=df['x'], # assign x as the dataframe column 'x'


layout = go.Layout(

fig = go.FigureWidget(data=data, layout=layout)

# IPython notebook
# py.iplot(fig, filename='pandas-bar-chart-layout')


# IPython notebook
# py.iplot(fig, filename='pandas-bar-chart-layout')

def updatePlot(yValues):
    N = resolution
    x = np.linspace(1, 100, 100)
    y = np.arange(0,100)*2*yValues
    y2 = np.arange(0,100)*yValues
    y3 = np.random.randn(N)+9
    updatedYValues= [y,y2,y3]
    for plotObject in range(len(
        bar =[plotObject]
        bar.y = updatedYValues[plotObject]
interact(updatePlot, yValues=(0,100))

Would be really interested in anysolution of how i can update my stackplot via sliders. Iam open for any suggestions, the graph must not be plotly at all( also it would be very nice to have all the interactivity of a plotly graph).

Hi @Varlor,

This FigureWidget example might be a helpful reference: An important thing about using a FigureWidget is that you should let it display itself in the notebook (or use IPython.display.display), and you should not use iplot, which doesn’t support updates.


Worked for me now, perfect thank you!!!

1 Like