Python Forum

Full Version: Plotting data over a year
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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())
Is this school/homework assignment?
Yes it is
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
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?
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
okay,thank you anyway
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?
Please, don't start new thread. I merged your new thread in the original one