我最近发现了 plotly 并发现它非常适合绘图,现在我有一个问题,我想将多个 plot 保存到一个 html 中,请问怎么做?
*我想保存多个情节,即无花果,无花果1,无花果2等等,而不是一个有多个情节的子情节,因为我发现子情节中的情节太小了。
Mil*_*l0s 36
在 Plotly API 中有一个函数to_html可以返回图形的 HTML。此外,您可以设置选项参数full_html=False,它只会为您提供包含图形的 DIV。
您可以通过附加包含数字的 DIV 将多个数字写入一个 HTML:
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'))
Run Code Online (Sandbox Code Playgroud)
https://plot.ly/python-api-reference/generated/plotly.io.to_html.html
您还可以使用 Beautiful Soup 进行 DOM 操作,并将 DIV 准确地插入到 HTML 中您需要的位置。
https://beautiful-soup-4.readthedocs.io/en/latest/#append