简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM