您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

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

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

offline.plot方法具有image='pngimage_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')
其他 2022/1/1 18:35:59 有431人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶