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:)

1
  • can you save the image as .png add the image within the html? (with the <img src="path_to_img.png"> tag?) Commented May 29, 2020 at 15:14

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

2 Comments

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?
How did you define plt please share more code. You can use pastebin if it doesnt fit in a comment

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.