0

So I know that i can save my diagramm with

plt.savefig('/home/pi/test.png')

But I don't really know how to save and display my diagramm with a HTML file. For my website it would be easier use a HTML file to display my data. So is it possible to save my diagramm in HTML and how?

If it helps here is my code:

from pandas import DataFrame
import sqlite3
import matplotlib.pyplot as plt
import pandas as pd

con = sqlite3.connect("/home/pi/test2.db")
df = pd.read_sql_query("SELECT * from data4 limit 79;",con)




df.plot(x = 'zeit', y = 'temp', kind ='line')
plt.savefig('/home/pi/test.png')
#plt.show()

I'm sorry if I did some mistakes I'm a beginner:)

Simon
  • 77
  • 1
  • 7

1 Answers1

0

As far as I know that is not possible with matplotlib But it is possible with https://mpld3.github.io/ and specifically this function: https://mpld3.github.io/modules/API.html#mpld3.fig_to_html

mpld3.fig_to_html(fig, d3_url=None, mpld3_url=None, no_extras=False, template_type='general', figid=None, use_http=False, **kwargs)
Output html representation of the figure
Uber
  • 331
  • 1
  • 5
  • 18
  • Thanks but when i run my this ( `mpld3.fig_to_html(plt, d3_url=None, mpld3_url=None, no_extras=False, template_type='general', figid=None, use_http=False` ) I get the Error: `AttributeError: module 'matplotlib.pyplot' has no attribute 'canvas'`. Do you know what the problem is? – Simon May 29 '20 at 16:04
  • How did you define plt please share more code. You can use pastebin if it doesnt fit in a comment – Uber May 29 '20 at 19:28