Plotting data over a year - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Plotting data over a year (/thread-10534.html) |
Plotting data over a year - xero1998 - May-24-2018 Hi! I want to plot movements over a year but dont get it to work. Do anyone have any suggestions that could help? class Corrections: def __init__(self, data): self.data=data def DataError (self): movements=[] date=[] time=[] for n in enumerate(self.data): c=n[1].split() date.append(c[0]) time.append(c[1]) movements.append(int(c[2])) LN=[] for n in range(len(time)-1): LN.append(int(time[n][0:2])*24*60+int(time[n][3:5])*60+int(time[n][6:8])) for k in range(len(LN)-1): if LN[k+1]-LN[k] > 160: LN.insert(k+1,LN[k]+120) date.insert(k+1,date[k]) movements.insert(k+1,movements[k]) for n in range(0, len(movements)-1): if movements[n+1]-movements[n]>4: movements[n+1]=movements[n]+4 if movements[n+1]<movements[n]: movements[n+1]=movements[n] movement=np.diff(movements) self.date=date self.LN=LN self.movement=movement Corrections(test).DataError() class Registeredmovements(Corrections: def __init__(self,givendate): self.givendate=givendate def plotting(self): Y=[] D=[] for i in [i for i,x in enumerate(self.date) if x==givendate]: return i Y.append(self.date=date[i:i+281050]) D.append(self.LN=LN[i:i+281050]) M.append(self.movements=movements[i:i+281050]) plot(Y,M) plt.show() print(Registeredmovements('2015-01-25').plotting()) RE: Plotting data over a year - buran - May-24-2018 Is this school/homework assignment? RE: Plotting data over a year - xero1998 - May-24-2018 Yes it is RE: Plotting data over a year - buran - May-24-2018 sorry to say that, but to be honest your code is total mess. before you start thinking of plotting your data you need to be able to read your data in suitable format and you can print meaningful data. At the moment your code is full of errors RE: Plotting data over a year - xero1998 - May-24-2018 I´ve got my data but don´t know what I should do to make it work. So not evan the correction class is right? RE: Plotting data over a year - buran - May-24-2018 From a quick look I don't see obvious errors, like there are in the Registeredmovements class (whee you have even obvious Syntax errors). But of course I cannot test. Also, I'm not sure what Corrections class should/is expected to yield. However there are plenty of stuff that can be written better/in more pythonic way RE: Plotting data over a year - xero1998 - May-24-2018 okay,thank you anyway Sum data - xero1998 - May-28-2018 Hi! I have a question about how to sum data from a file over a year. The file have about 720 data values in one day and i want to make that into a list over a hole year and then plot it. Can anyone help me? RE: Plotting data over a year - buran - May-28-2018 Please, don't start new thread. I merged your new thread in the original one |