Not Able to Save Plotly Plots Using To_Image or Write_Image [Duplicate]
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...
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.
3 Answers
Try this version of kaleido.
pip install kaleido==0.1.0post1
It works for me
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
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