Update barchart data in subplot is not possible

Hi, I have problem to update a bar plot in a Jupyter notebook. If i have the barplot as a single plot it works without problems but when i insted try to update the y-data when the barplot is a part of a subplot the figure in the notebook won’t update in spite of the fig.data[0].y is updated. Somehow plotly don’t notice the change and do not update the plot. Anyone out there that can explain why it fails, and maybe come up with a solution?
Thanks,
Jonas

import plotly.offline as py
import plotly.graph_objs as go
from plotly import tools

def subplot(x=[‘giraffes’, ‘orangutans’, ‘monkeys’],y=[20, 14, 23]):
fig=tools.make_subplots(rows=1,cols=2)
trace=go.Bar(x=x,y=y)
fig.append_trace(trace,1,2)
return fig

def updateSubplot(fig,y):
with fig.batch_update():
fig.data[0].y=y

fig=subplot()
py.iplot(fig,filename=‘test’)
updateSubplot(fig,y=[20, 1, 23])

Hi @overklighten,

In order for the figure to update, the figure must be a go.FigureWidget instance and it must be allowed to display itself (it should not be displayed with plot/iplot). The tools.make_subplots function returns a go.Figure instance not go.FigureWidget so you’ll need to convert it.

import plotly.offline as py
import plotly.graph_objs as go
from plotly import tools

def subplot(x=['giraffes', 'orangutans', 'monkeys'], y=[20, 14, 23]):
    fig=tools.make_subplots(rows=1,cols=2)
    trace=go.Bar(x=x,y=y)
    fig.append_trace(trace,1,2)
    return go.FigureWidget(fig)

def updateSubplot(fig,y):
    with fig.batch_update():
        fig.data[0].y=y

fig=subplot()
fig

newplot%20(3)

updateSubplot(fig,y=[20, 1, 23])

Hope that helps!
-Jon

1 Like

Thanks a lot, that gives me some more insight! The difference between the different figure objects has not been clear for me bu now I’m getting closer… :slight_smile:

Thanks again!
/Jonas

1 Like