You’ll need to run the following commands to download a Plotly Express chart as an image when using Google Colab.
You’ll see I am using %%capture
which is a magic command to hide the output.
%%capture !pip install kaleido !pip install plotly>=4.0.0 !wget https://github.com/plotly/orca/releases/download/v1.2.1/orca-1.2.1-x86_64.AppImage -O /usr/local/bin/orca !chmod +x /usr/local/bin/orca !apt-get install xvfb libgtk2.0-0 libgconf-2-4
Once you run that code, then you can save you chart by using this code: fig.write_image("image.png")
. Here’s an example:
import plotly.graph_objects as go import numpy as np x = np.arange(10) fig = go.Figure(data=go.Scatter(x=x, y=x**2)) fig.show() fig.write_image("image.png")
Final Thoughts
Check out more Python tricks in this Colab Notebook or in my recent Python Posts.
Thanks for reading!