I have a small app which generates a graph and saves it to a file. The file is then displayed using a reference. My question is, is it better to use matplotlib.pyplot SaveFig function or matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas function? Here is an extract of my code:
-- Views:
from django.shortcuts import render
from . import graphs
from django.conf import settings as djangoSettings
import os.path
def graph(request):
from datetime import datetime, timedelta
datetoday,datef = interDateFunction()
graph_filename = (djangoSettings.STATICFILES_DIRS[0] + 'graph_' + datetoday + '.png')
filename = ('graph_' + datetoday + '.png')
if not os.path.exists(graph_filename):
graphs.genGraph(graph_filename)
args = {'Value':'Generated','DateF':datef,'Filename':filename}
return render(request, 'graphs/home.html', args)
else:
args = {'Value':'FromCache','DateF':datef,'Filename':filename}
return render(request, 'graphs/home.html', args)
The view references code in the graphs.py:
def genGraph(graph_filename):
dtStart = (dt.datetime.strptime("2015-01-01", '%Y-%m-%d'))
datast = data.get_data_google('TSCO.L', dtStart)['Close']
fig,ax = plt.subplots()
ax.plot(datast)
fig.savefig(graph_filename)
plt.close(fig)
return True
I have seen examples where they use matplotlib.backends.backend_agg function FigureCanvasAgg. Which is better to use with django?
Thanks,
Khi.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d56baf8c-eb5c-4439-8b77-17094b069759%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment