i wanted to create a django aplication which shows the graph using the data in the csv. I write a code in views file of the application repository. and also i placed the csv file along with views.py file. The codes are as follows
#from django.shortcuts import render
import sys
from sys import *
import numpy as np
import matplotlib.pyplot as xy
from datetime import datetime
from matplotlib.dates import YearLocator, MonthLocator, DateFormatter
from matplotlib.ticker import Formatter
import PIL
import PIL.Image
import StringIO
from django.http import HttpResponse
from django.template import RequestContext, loader
import csv
def graph():
a=[]
b=[]
c=[]
h=[]
a1=[]
b1=[]
c1=[]
j= open("Tier 1 Lake.csv")
for row in csv.reader(j):
a.append(row[8])
b.append(row[28])
c.append(row[2])
for i,v in enumerate(a):
if b[i]:
a1.append(a[i])
b1.append(b[i])
c1.append(c[i])
d=[item for item in range(len(c1)) if c1[item] == 'JOR-01-L']
e=[a1[i] for i in d]
f=[b1[i] for i in d]
FORMAT = '%m/%d/%Y'
s = sorted(zip(e,f), key = lambda x: datetime.strptime(x[0],'%m/%d/%Y'))
r= [x[1] for x in s]
t= [x[0] for x in s]
g= len(e)
for k in range(0,g):
h.append(k)
fig, ax = xy.subplots()
fig.autofmt_xdate()
xy.plot(h,r)
xy.xticks(h,t)
xy.plot(r, '-o', ms=10, lw=1, alpha=1, mfc='orange')
xy.xlabel('Sample Dates')
xy.ylabel('Air Temperature')
xy.title('Tier 1 Lake Graph (JOR-01-L)')
xy.grid(True)
xy.show()
buffer = StringIO.StringIO()
canvas = pylab.get_current_fig_manager().canvas
canvas.draw()
graphIMG = PIL.Image.fromstring("RGB", canvas.get_width_height(), canvas.tostring_rgb())
graphIMG.save(buffer,"PNG")
xy.close()
return HttpResponse(buffer.getvalue(), content_type="image/png")
Links and urls are functioning absolutely fine. THE ERROR I AM GETTING IS " No such file or directory: 'Tier 1 Lake.csv'-- IO Error"