Temperature vs time plot

Hii all,

I have taken some data from a instrument. These data contain the temperature with time. A part of the data looks like,

00:00:08
section A 76.21
section B 76.54
section C 76.66
section D 77.87
00:15:30
section A 76.23
section B 76.89
section C 77.98
section D 78.60

and the file continues till end.
00:00:08 means 00 hour , 00 minutes and 08 seconds.

Now I need to read this data and make a plot of the temperature with the time.

My code till now is following,

import matplotlib.pyplot as plt
import matplotlib.cm as cm
from matplotlib.dates import DateFormatter
from datetime import datetime
import re
def main():
file = r"C:\Users\sarad\ss1.dat.log"
index =
month =
day =
year =
hour =
minute =
second =
s1 =
s2 =
s3 =
s4 =
s5 =
s6 =
s7 =
s8 =
with open(file) as line:
while True:
result=re.findall(r"(\d+(?:.\d+){0,1})",line.read())
if not result:
break
hour.append(int((result[0])))
minute.append(int((result[1])))
second.append(int((result[2])))
s1.append(float(result[3]))
s2.append(float(result[4]))
s3.append(float(result[5]))
s4.append(float(result[6]))
s5.append(float(result[7]))
s6.append(float(result[8]))
s7.append(float(result[9]))
s8.append(float(result[10]))

I have to use loop somehow and read all the datas . I can not understand how to take the time also.

Could you give some idea ?

Thank you.

(suggestion: surround code with three backticks (```, top left of a US keyboard) to format it with indentation)

This kind of file is annoying because the information you need is spread over different lines, so you need to keep track. A pattern I tend to use is something like this:

with open(file_name) as fh:
    timestamp = None
    timestamp_to_data = defaultdict(dict)
    for line in fh:
        if line[0] in '012':  # this line starts with a number
            timestamp = some_function_to_parse_the_time(line)
        elif line.startswith("section"):
            _, section, data = line.strip().split()
            timestamp_to_data[timestamp][section] = data
        else:
            raise ValueError("something weird on this line?")

Basically, each line you check for a new time and update the timestamp variable if you find it. Otherwise you parse the data for the current time. If there’s anything else in the file it will raise an error–maybe you need to add additional parsing rules.

This would make a dictionary of dictionaries: one for each time, containing the data for each section inside. I didn’t figure out all the parsing here but it looks like you figured that part out.

Hope this helps!