Black Lives Matter. Please consider donating to Black Girls Code today.

Create static plotly figure in Jupyter with Python

Hi, I use plotly (Python bindings) inside of Jupyter notebooks for teaching. Specifically, I create plots with plotly.offline.iplot. However, when I push the Jupyter notebook to GitHub and have my students view the static notebook (rendered by GitHub) in their web browsers, the plotly figures don’t show up. Does anyone know how to solve this? For example, is there a way for me to create a second, non-interactive version of the plot that gets embedded into the Jupyter notebook (like a matplotlib figure does)? That way, people who have actually loaded the notebook in Jupyter could play with the interactive plot, but people just viewing the static rendering of the notebook in a browser at least get to see a frozen static view of the plot.


Your best bet is to upload your notebooks to Chart Studio Cloud at … we have special handling there for rendering notebooks with interactive Plotly charts, like this:

In this case my workflow requires GitHub Enterprise so I won’t be able to take that avenue. But even knowing there isn’t some obvious convenient approach is good - this way I won’t spend hours trying to figure it out. Thanks Nicolas!

I figured out how to do this. First

import as pio
from IPython.display import Image

Then, if the plotly figure is stored in fig, you can display a static rendering inline in Jupyter with

Image(pio.to_image(fig, format='png'))

Reference link: