🏥 🏭 Working on the COVID-19 response in Canada? Plotly & the Canadian government can help you and your organization. Learn more and get in touch.

Possible to update the data for a scatter in offline mode in a python notebook?

Although I’ve found a bunch of examples showing how to connect an iPywidget to a plotly graph, they all seem to use a GraphWidget which requires a URL. I have a simple line/scatter plot with two traces and want to shift one of the traces left or right based on the value of an ipywidget slider. I have it partly working in that when I move the slider I can get a new scatter plot with one of the traces correctly shifted. However, I haven’t been able to figure out how to update/refresh the graph that is currently displayed to use the modified data. Subsequent calls to iplot() after changing the trace create additional copies of the graph. I tried putting the plotly scatter in an output widget and clearing the Scatter and replacing it with a new one, which doesn’t result in many copies of the scatter but is unusably “clunky”, not to mention inefficient to recreate the entire figure every time the slider moves.

I also found the postMessage API which looked promising until I realized it’s only for javascript. Is there any way that I can update the data and trigger a refresh of a Scatter/Line chart that has been displayed using iplot in offline mode in a python jupyter notebook?

Here’s an example that might do what you’re talking about.

Great. That is exactly the kind of things I was looking for. Although it flickers a bit when the graph is redrawn (double buffing would be useful here) at least I now can see how to update a graph in a notebook.

Any change you’ve figured out how to just refresh the plot, rather than redraw?