eemeter
eemeter copied to clipboard
Add a figure parameter to the visualization methods
One issue with the current usage of pyplot is with webservers, for example the current plot code crashes (not an exception just a good old process crash) my python instance running Django ... One alternative that works for me and could be useful to others is to use matplotlib.figure instead of pyplot (as recommended here https://matplotlib.org/faq/howto_faq.html#howto-webapp ) so for example this code is equivalent to the tutorial visualization section and produces the same graph without crashing (later for example one can base64 encode the image and stream it to a client, or store in a DB or upload it directly) :
from matplotlib.figure import Figure
from io import BytesIO
fig = Figure(figsize=(10, 4))
ax = eemeter.plot_energy_signature(data['meter_data'], data['temperature_data'], figure=fig)
model.plot(
ax=ax, figure=fig, candidate_alpha=0.02, with_candidates=True, temp_range=(-5, 88)
)
buf = BytesIO()
fig.savefig(buf, format="png")