我在ubuntu22.04中尝试了下面的代码,它工作正常。但是当我在 windows11 中运行相同的代码时(python 3.12,plotly 5.20.0),它挂在写入图像行。
#!/usr/bin/env python3
#%%
import plotly.graph_objects as go
fig = go.Figure(
data=[go.Scatter(x=[0, 1], y=[0, 1])],
layout=go.Layout(
xaxis=dict(range=[0, 5], autorange=False),
yaxis=dict(range=[0, 5], autorange=False),
title="Start Title",
updatemenus=[dict(
type="buttons",
buttons=[dict(label="Play",
method="animate",
args=[None])])]
),
frames=[go.Frame(data=[go.Scatter(x=[1, 2], y=[1, 2])]),
go.Frame(data=[go.Scatter(x=[1, 4], y=[1, 4])]),
go.Frame(data=[go.Scatter(x=[3, 4], y=[3, 4])],
layout=go.Layout(title_text="End Title"))]
)
pngname = "demo.png"
print("save start")
fig.write_image(pngname,format="png",width=800,height=500)
print("save image done")
打印出来的
save start
会永远挂起,C-c
也不能中断它。
这显然是 Plotly 中一个持续存在的问题,尚未得到解决。 此帖子建议将用于静态图像生成的 Kaleido 包降级到旧版本
kaleido==0.1.0.post1
。