Peter S
Peter S

Reputation: 575

Plot same TimePeriod from Multiple Days

My Data Looks like this: File_A

2015-08-01 00:00    424.9563018750976
2015-08-01 00:01    785.7380434263472
....
2015-08-01 23:59

File_B

2015-08-02 00:01    1.4625096463725384
2015-08-02 00:02    6.0047607076482485
....
2015-08-02 23:59

So the Date Format is: %Y-%m-%d %H:%M I'd like to plot a series for the whole month but for each day only the timeperiod fom e.g. 09:00 - 15:00.

Here's what I tried:

clear
reset
cd 'C:\Users\SammerP\Desktop\Desktop Calc\AIT ALL\CatchAllDataAIT\data'
set title 'Data of Month' font 'bold verdana,08'
set xdata time
set timefmt '%Y-%m-%d %H:%M'
set format x '%Y-%m-%d %H:%M'
set ylabel 'Value' 
set yrange [550:700]
set ytics (550,560,570,580,590,600,610,620,630,640,650,660,670,680,690,700,710,720,730,740,750,760,770,780,790,800)
set xtics rotate by 45 offset -1.5,-1.2
set xrange ['2014-08-01 09:00':'2014-08-31 15:00']

set xtics ('08-01' '2014-08-01 13:00','08-02' '2014-08-02 13:00','08-03' '2014-08-03 13:00','08-04' '2014-08-04 13:00','08-05' '2014-08-05 13:00',\
'08-06' '2014-08-06 13:00','08-07' '2014-08-07 13:00','08-08' '2014-08-08 13:00','08-09' '2014-08-09 13:00','08-10' '2014-08-10 13:00','08-11' '2014-08-11  13:00',\
'08-12' '2014-08-12 13:00','08-13' '2014-08-13 13:00','08-14' '2014-08-14 13:00','08-15' '2014-08-15 13:00','08-16' '2014-08-16 13:00',\
'08-17' '2014-08-17 13:00','08-18' '2014-08-18 13:00','08-19' '2014-08-19 13:00','08-20' '2014-08-20 13:00','08-21' '2014-08-21 13:00',\
'08-22' '2014-08-22 13:00','08-23' '2014-08-23 13:00','08-24' '2014-08-24 13:00','08-25' '2014-08-25 13:00','08-26' '2014-08-26 13:00',\
'08-27' '2014-08-27 13:00','08-28' '2014-08-28 13:00','08-29' '2014-08-29 13:00','08-30' '2014-08-30 13:00','08-31' '2014-08-31 13:00')
set grid
set nokey
plot'File_A.csv' using 1:2 axes x1y1 linewidth 1 lc rgb 'red' w l,\
'File_B' using 1:2 axes x1y1 linewidth 1 lc rgb 'red' w l,
..........

I tried it by plotting only the certain line from each file but than I end up with hole between the days. I thought that maybe the problem was the xrange setting so I deleted that but the Problem was the same

Is there a way to set the xrange so that Gnuplot plots From Day 1 to 31, every Day from 09:00 from 15:00 and without the empty spaces between the days.

Here's an example of how it looks like now:

enter image description here

Upvotes: 2

Views: 464

Answers (1)

Christoph
Christoph

Reputation: 48390

That cannot be done automatically with gnuplot. In my opinion, your best option is to not use a time-axis, but a normal numerical axis and provide your own mapping to label the xtics properly and to adjust the gap between the days like you want.

Here is a possible solution, but without having proper data for testing I couldn't verify if I got all steps correct:

gapBetweenDaysInSeconds = 1000
startHour = 9.0
endHour = 15.0

set xtics ("01-08" (13-startHour)*60*60)
set for [i=2:31] xtics add (sprintf("08-%02d", i) ((i-1)*(endHour-startHour) + 13 - startHour)*60*60 + (i-1)*gapBetweenDaysInSeconds)

# for gnuplot 5.0
# gettime(col) = timecolumn(col, '%Y-%m-%d %H:%M')
# for all gnuplot version.
gettime(col) = strptime('%Y-%m-%d %H:%M', strcol(col).' '.strcol(col+1))

files="File_A.csv File_B.csv File_C.csv" # ... to be continued

plot for [file in files] file using (t=gettime(1), tm_hour(t) < startHour || tm_hour(t) >= endHour ? 1/0 : (((tm_mday(t)-1)*(endHour-startHour) + (tm_hour(t)-startHour))*60 + tm_min(t))*60 + tm_sec(t) + (tm_mday(t)-1)*gapBetweenDaysInSeconds):2 lt 1

That assumes, that you have one file per day, and those files are listed, separated by white spaces, in the variable files.

The first call to set xtics sets only a single xtic and deletes all other. Then I use set xtics add to add all following tics in a loop.

For each row, the time stamp is parsed using the gettime user-defined function and assigned to the variable t. In a second step I extract only the day of the mont, hour, minutes and seconds using the tm_* functions and calculate a position on the xaxis given in seconds since the first of the respective month. The gap between two days can be given using the variable gapBetweenDaysInSeconds.

At the moment the month is hardcoded to 08.

That should be a reasonable starting point.

Upvotes: 2

Related Questions