将多个图保存到单个 html 中 [英] Plotly saving multiple plots into a single html

查看:135
本文介绍了将多个图保存到单个 html 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近发现了 plotly 并发现它非常适合绘图,现在我有一个问题,我想将多个 plot 保存到单个 html 中,请问怎么做?

I recently discovered plotly and find it really good for graphing, now I have a problem which I want to save multiple plot into a single html, how to do it please?

*我想保存多个 plot,即 fig、fig1、fig 2 等等,而不是一个有多个 plot 的 subplot,因为我发现 subplot 中的 plot 太小了.

*I want to save multiple plot, i.e fig, fig1, fig 2 and so on, NOT one subplot which has multiple plot in it, because I found that the plot within subplot is too small.

推荐答案

在 Plotly API 中有一个函数 to_html 返回图形的 HTML.此外,您可以设置选项参数 full_html=False 这会给你只包含数字的 DIV.

In the Plotly API there is a function to_html which returns HTML of the figure. Moreover, you can set option param full_html=False which will give you just DIV containing figure.

您可以通过附加包含数字的 DIV 将多个数字写入一个 HTML:

You can just write multiple figures to one HTML by appending DIVs containing figures:

with open('p_graph.html', 'a') as f:
    f.write(fig1.to_html(full_html=False, include_plotlyjs='cdn'))
    f.write(fig2.to_html(full_html=False, include_plotlyjs='cdn'))
    f.write(fig3.to_html(full_html=False, include_plotlyjs='cdn'))

https://plot.ly/python-api-参考/生成/plotly.io.to_html.html

您还可以使用 Beautiful Soup 进行 DOM 操作,并将 DIV 准确地插入到 HTML 中您需要的位置.

You can also use Beautiful Soup to do DOM manipulation and insert DIV exactly where you need it in the HTML.

https://beautiful-soup-4.readthedocs.io/en/latest/#append

这篇关于将多个图保存到单个 html 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆