Plotly saving multiple plots into a single html

前端 未结 3 1541
臣服心动
臣服心动 2021-02-01 09:57

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?

*I wa

3条回答
  •  南方客
    南方客 (楼主)
    2021-02-01 10:33

    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.

    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-reference/generated/plotly.io.to_html.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

提交回复
热议问题