如何以png格式保存Plotly Offline图?

如何以png格式保存Plotly Offline图?,第1张

如何以png格式保存Plotly Offline图?

offline.plot
方法具有
image='png
image_filename='image_file_name'

属性,可将文件另存为
png

offline.plot({'data': [{'y': [4, 2, 3, 4]}],    'layout': {'title': 'Test Plot',    'font': dict(family='Comic Sans MS', size=16)}},  auto_open=True, image = 'png', image_filename='plot_image',  output_type='file', image_width=800, image_height=600,   filename='temp-plot.html', validate=False)

在上

offline.py
或在线查看更多详细信息
plotly

但是,有一点需要注意的是,由于输出图像是与HTML绑定的,因此它将在浏览器中打开,并要求获得保存图像文件的权限。您可以在浏览器设置中将其关闭。

或者,您可能希望使用查看从plotly到matplotlib的转换

plot_mpl

以下示例来自
offline.py

from plotly.offline import init_notebook_mode, plot_mpl    import matplotlib.pyplot as plt    init_notebook_mode()    fig = plt.figure()    x = [10, 15, 20, 25, 30]    y = [100, 250, 200, 150, 300]    plt.plot(x, y, "o")    plot_mpl(fig)    # If you want to to download an image of the figure as well    plot_mpl(fig, image='png')


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5646080.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存