Plotly 将多个绘图保存到单个 html 中
·
回答问题
我最近发现 plotly 并发现它非常适合绘图,现在我有一个问题,我想将多个绘图保存到一个 html 中,请问该怎么做?
*我想保存多个图,即图,图1,图2等等,而不是一个有多个图的子图,因为我发现子图中的图太小了。
Answers
在 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'))
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
更多推荐

所有评论(0)