【问题标题】:How to save plotly image to local file with javascript如何使用javascript将绘图图像保存到本地文件
【发布时间】:2023-02-06 10:30:42
【问题描述】:

使用 javascript 将绘图保存到本地文件的正确方法是什么?

img_png.attr("src", url);
Plotly.toImage(gd,{format:'png',height:400,width:400});

以上代码来自官方文档保存到element,我想直接保存到本地磁盘!

【问题讨论】:

  • fig.write_image('filename') 详情见Reference中的保存图片。

标签: plotly


【解决方案1】:

您将从Plotly.toImage() 获得使用 base64 字符串编码的图像,您可以通过多种方式将 base64 字符串转换为图像。 (例如this page

假设 html 代码是这样的

<div id="chart">
  <!-- chart here -->
</div>

那么javascript代码应该是这样的

Plotly.toImage('chart', { format: 'png', width: 800, height: 600 }).then(
    function (dataUrl) {
    // use the dataUrl
})

希望这有帮助!

【讨论】:

    猜你喜欢
    • 2020-05-31
    • 2016-03-09
    • 1970-01-01
    • 2011-03-01
    • 2020-05-10
    • 2014-03-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多