繁体   English   中英

如何将 plotly 图形保存为 jpg

[英]How do I save plotly graph as jpg

如何将在graph.show()之后创建的以下图形保存为 JPG、PNG 或 PDF 到特定目录?

代码

    import plotly.graph_objects as go

    graph = go.Figure(data=[go.Candlestick(x=df['Date'],
                open=df['AAPL.Open'], high=df['AAPL.High'],
                low=df['AAPL.Low'], close=df['AAPL.Close'])
                      ])

    graph.show()

一个简单的谷歌搜索告诉我

graph.write_image("name_of_file.jpeg")

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

这将起作用:

graph.write_image("name_of_file.jpeg")

但是你必须安装万花筒。 plotly 文档中,您可以看到:

Static image generation requires either Kaleido (recommended, supported as of plotly 4.9) or orca (legacy as of plotly 4.9). The kaleido package can be installed using pip.

$ pip install -U kaleido

或康达。

$ conda install -c plotly python-kaleido

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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