Hi everyone.. I'm new to python, the more to matplotlib :( and I am hoping that I can get help from this community... :)

I have a .csv file, first column is a time stamp with format HH:MM:SS, next 8 columns are values of different parameters.

I want to plot each parameter against the time it is taken, in this case, against the time as indicated by the time stamp...

How do I convert the time stamp into something which is can be understood by matplotlib? please help me on this... :)

Thank you!

Hi everyone.. I'm new to python, the more to matplotlib :( and I am hoping that I can get help from this community... :)

I have a .csv file, first column is a time stamp with format HH:MM:SS, next 8 columns are values of different parameters.

I want to plot each parameter against the time it is taken, in this case, against the time as indicated by the time stamp...

How do I convert the time stamp into something which is can be understood by matplotlib? please help me on this... :)

Thank you!

You can try something like

# python 2 or 3
from datetime import datetime
zero = datetime.strptime("00:00:00", "%H:%M:%S")

def seconds_since_midnight(stime):
    return (datetime.strptime(stime, "%H:%M:%S") - zero).seconds

print(seconds_since_midnight("10:31:27"))

""" my output ->
37887
"""

You could also define this

# python 2 or 3
def seconds_since_midnight(stime):
    h, m, s = (int(x) for x in stime.split(":"))
    return 3600 * h + 60 * m + s

uhmm... it's like this... I have a .csv file, inside this file (when open in msExcel) is something like:

00:00:00 30 42 23 -98 42 23 64 16 23
00:00:15 40 25 57 24 23 24 45 32 13
00:00:30 20 64 13 11 12 98 87 12 11
00:00:45 10 23 -90 09 12 17 56 98 42

What I need to do is to get the time stamp, use it as range in the x-axis... and take one column of the values for th y-values.

i.e. column 1:


50
40 x
30 x
20 x
10 x
0
00:00:00 00:00:15 00:00:30 00:00:45

something like that... :(

I think Gribouillis function works beautifully. Just use that for time column and use int() for other values in line. Post your code and error messages and description of your efforts to solve the problem if you get stuck.

Hi.. I tried the code, thank you so much:

import csv
from matplotlib.dates import num2date
from datetime import datetime
from time import strftime

#opening the file
dampdata = csv.reader(open("plottime.csv",))

#making the time array
time = []
for data in dampdata_list:
    time.append(data[0])

i=0
while (i!=25): #25 will be changed to 1439 when all data are in
    forxaxis = datetime.strptime(time[i], "%H:%M:%S")
    print forxaxis
    i=i+1

my result is:

1900-01-01 00:00:01
1900-01-01 00:00:15
1900-01-01 00:00:30
1900-01-01 00:00:45
1900-01-01 00:01:00
1900-01-01 00:01:15
1900-01-01 00:01:30
1900-01-01 00:01:45
1900-01-01 00:02:00
1900-01-01 00:02:15
1900-01-01 00:02:30
1900-01-01 00:02:45
1900-01-01 00:03:00
1900-01-01 00:03:15
1900-01-01 00:00:30
1900-01-01 00:03:45
1900-01-01 00:04:00
1900-01-01 00:04:15
1900-01-01 00:04:30
1900-01-01 00:04:45
1900-01-01 00:05:00
1900-01-01 00:05:15
1900-01-01 00:05:30
1900-01-01 00:05:45
1900-01-01 00:06:00

Concern: how can I remove the date? I am only interested with the time... time[] doesn't contain dates too, I don't know why the 1900-01-01 date appears... help!

Hi.. I tried the code, thank you so much:

import csv
from matplotlib.dates import num2date
from datetime import datetime
from time import strftime

#opening the file
dampdata = csv.reader(open("plottime.csv",))

#making the time array
time = []
for data in dampdata_list:
    time.append(data[0])

i=0
while (i!=25): #25 will be changed to 1439 when all data are in
    forxaxis = datetime.strptime(time[i], "%H:%M:%S")
    print forxaxis
    i=i+1

my result is:

1900-01-01 00:00:01
1900-01-01 00:00:15
1900-01-01 00:00:30
1900-01-01 00:00:45
1900-01-01 00:01:00
1900-01-01 00:01:15
1900-01-01 00:01:30
1900-01-01 00:01:45
1900-01-01 00:02:00
1900-01-01 00:02:15
1900-01-01 00:02:30
1900-01-01 00:02:45
1900-01-01 00:03:00
1900-01-01 00:03:15
1900-01-01 00:00:30
1900-01-01 00:03:45
1900-01-01 00:04:00
1900-01-01 00:04:15
1900-01-01 00:04:30
1900-01-01 00:04:45
1900-01-01 00:05:00
1900-01-01 00:05:15
1900-01-01 00:05:30
1900-01-01 00:05:45
1900-01-01 00:06:00

Concern: how can I remove the date? I am only interested with the time... time[] doesn't contain dates too, I don't know why the 1900-01-01 date appears... help!

Why are you not usin g the conversion to seconds?

because that is not the application I need...?

because that is not the application I need...?

Start writing a full working plot with seconds, then you can concentrate on this time problem. You can post your app here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.