Shrom
Shrom

Reputation: 243

Not able to save plotly plots using to_image or write_image

fig.write_image("images/fig1.png",format='png',engine='kaleido')

This makes my VSCode go bananas, the terminal hangs and the program stops then and there. Everything works fine if I remove just that line.

I want to save the plots as pngs, but it is not working. I have kaleido installed.

Upvotes: 24

Views: 28535

Answers (3)

Thang Pham
Thang Pham

Reputation: 1

Please follow what Gillian Grayson suggested. I am using Jupyter Notebook, Plotly version 5.13.0 and Kaleido 0.1.0.post1 and Python 3.8

Also add this to make saving figure faster

import plotly plotly.io.kaleido.scope.mathjax= None

Upvotes: 0

Gillian Grayson
Gillian Grayson

Reputation: 533

Try this version of kaleido.

pip install kaleido==0.1.0post1

It works for me

Upvotes: 38

Rob Raymond
Rob Raymond

Reputation: 31226

Complete MWE. png gets created as expected.

import plotly.graph_objects as go
import numpy as np
from pathlib import Path

f = Path.cwd().joinpath("images")
if not f.is_dir(): f.mkdir()
f = f.joinpath("fig1.png")

fig = go.Figure(go.Scatter(x=np.linspace(1,10,100), y=np.sin(np.linspace(-np.pi,np.pi, 100))))

fig.write_image(f,format='png',engine='kaleido')

versions

import plotly
import kaleido

print(plotly.__version__, kaleido.__version__)
5.5.0 0.2.1

Upvotes: 2

Related Questions