Member Avatar for dumicom

Hi, this program of mine can plot timestamp & irradiance but how can i plot another line of data for temperature?

This is my txt data:

TimeStamp,Irradiance,Temperature
21/7/2014 0:00,0.66,26.2
21/7/2014 0:00,0.71,23.4
21/7/2014 0:00,0.65,25.4
21/7/2014 0:00,0.67,25.3
21/7/2014 0:01,0.58,30.5
21/7/2014 0:01,0.54,26.7
21/7/2014 0:01,0.63,25.5
21/7/2014 0:01,0.65,26.9
21/7/2014 0:02,0.64,22.2

and this is a snippet of my code:

    from datetime import datetime
    import matplotlib.pyplot as plt
    import matplotlib.dates as mdates
    import numpy as np
    from scipy.stats import mode
    import re
    linematchregex = re.compile('(\d+/\d+/\d+ \d+:\d+),(\d+\.\d+)')

    startTime = datetime.strptime(raw_input('please enter start time in format like 21/7/2014 0:00 :'), '%d/%m/%Y %H:%M')
    endTime   = datetime.strptime(raw_input('please enter end time in format like 22/7/2014 23:57 :') , '%d/%m/%Y %H:%M')

with open(r'data.txt', 'r') as strm:
    strm.next() #skip first line
    t, y = zip(*[p for line in strm for p in linematchregex.findall(line)])
t = [datetime.strptime(x, '%d/%m/%Y %H:%M') for x in t ]
y = [float(x) for i,x in enumerate(y) if startTime<=t[i]<=endTime]

t = [x for x in t if startTime<=x<=endTime]
fig = plt.figure()
ax1 = fig.add_subplot(1, 1, 1, axisbg='white')
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%d/%m/%Y %H:%M'))
ax1.plot(t, y, 'c', linewidth=3.3)

plt.show()

thanks

Recommended Answers

All 7 Replies

This example from the pyplot examples page, plots two scales, and there are probably more.

Member Avatar for dumicom

Hi, i have tried editing my code and this is so far i have come up with but i got an error, a ValueError: need more than 2 values to unpack on the line 16 (the one in bold)

    from datetime import datetime
    import matplotlib.pyplot as plt
    import matplotlib.dates as mdates
    import numpy as np
    from scipy.stats import mode
    import re
    linematchregex = re.compile('(\d+/\d+/\d+ \d+:\d+),(\d+\.\d+)')

    startTime = datetime.strptime(raw_input('please enter start time in format like 21/7/2014 0:00 :'), '%d/%m/%Y %H:%M')
    endTime   = datetime.strptime(raw_input('please enter end time in format like 22/7/2014 23:57 :') , '%d/%m/%Y %H:%M')

with open(r'data.txt', 'r') as strm:
    strm.next() #skip first line
  **  t, y, temp = zip(*[p for line in strm for p in linematchregex.findall(line)])**
t = [datetime.strptime(x, '%d/%m/%Y %H:%M') for x in t ]
temp = [float(x) for i,x in enumerate(y) if startTime<=t[i]<=endTime]
y = [float(x) for i,x in enumerate(y) if startTime<=t[i]<=endTime]

t = [x for x in t if startTime<=x<=endTime]
fig = plt.figure()
ax1 = fig.add_subplot(1, 1, 1, axisbg='white')
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%d/%m/%Y %H:%M'))
ax1.plot(t, y, 'c', linewidth=3.3)
ax1.plot(t, temp)    
plt.show()

This question is a duplicate of this one in another forum.

Member Avatar for dumicom

sorry i will contact the moderator to delete this post

No need, as you are allowed to ask the same question across different sites (why wouldn't you be?) but you are not allowed to copy someone else's question/answer/editorial. Oh, and Gribouillis is a moderator - see the blue label under his name :)

Member Avatar for dumicom

oh ok since i never copy anyone content, guess i'm fine?

oh ok since i never copy anyone content, guess i'm fine?

It's not really the question. As a helper, I think it is useful to know that you are already getting help from someone else, not least because I can check if you already have a satisfactory answer. You already started many threads about different aspects of your program, and I think other helpers might want to check all the answers that you got.

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.