plotly保存静态图 (Static Image Export in Python)

https://plotly.com/python/static-image-export/

pip install kaleido

from kaleido.scopes.plotly import PlotlyScope
import plotly.graph_objects as go
import os
scope = PlotlyScope()
fig = go.Figure(data=[go.Scatter(y=[1, 3, 2])])
if not os.path.exists("images"):
    os.mkdir("images")
with open("./images/figure.png", "wb") as f:   # 在本地目录下面就会生成文件
    f.write(scope.transform(fig, format="png"))

你可能感兴趣的:(plotly保存静态图 (Static Image Export in Python))