Generating plots using FigureWidget in a for loop

Hello,

I’m rewriting some existing code in Jupyter notebooks to leverage the plot.ly 3.x APIs. I’m following the migration guide (https://github.com/plotly/plotly.py/blob/master/migration-guide.md). In the example:

import plotly import plotly.graph_objs as go
f = go.FigureWidget()
f # printing the widget will display it

“This means that plotly.offline.iplot and plotly.offline.init_notebook_mode() are no longer required (although still supported).”

It states that iplot is no longer required. I’m generating plots in a for loop and was previously using iplot for this. If I just “print” the figure object is indicated above, the plots don’t appear.

What’s the proper method in plot.ly 3.x to display FigureWidget plots from a loop?

Hi @argoneus,

You can display FigureWidgets inside a loop (or function) using the IPython display method: See https://ipywidgets.readthedocs.io/en/stable/examples/Widget%20Basics.html#display()

Hope that helps!
-Jon

1 Like

I tried using display(), but received the error:

Error displaying widget

I installed plotlywidget@0.4.0 and it’s working now. Thanks!

1 Like