美文网首页
plotly保存静态图 (Static Image Export

plotly保存静态图 (Static Image Export

作者: 饥人谷_流水 | 来源:发表于2021-03-10 23:52 被阅读0次

    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

          本文链接:https://www.haomeiwen.com/subject/xhzgqltx.html