Python >> Tutoriel Python >  >> Python Tag >> Plotly

Plotly enregistrer plusieurs parcelles dans un seul html

Dans l'API Plotly il y a une fonction to_html qui renvoie le HTML de la figure. De plus, vous pouvez définir l'option param full_html=False qui vous donnera juste DIV contenant la figure.

Vous pouvez simplement écrire plusieurs chiffres dans un code HTML en ajoutant des DIV contenant des chiffres :

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

Vous pouvez également utiliser Beautiful Soup pour effectuer des manipulations DOM et insérer DIV exactement là où vous en avez besoin dans le HTML.

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