How can I pair and rename x-axis double rename 2 by 1 in gnuplot - gnuplot

I want to add hours and group within itself by date. It is, but want to show on x-axis. I tried this but couldn't use properly. Getting following error.
"gnuplot.gnu" line 16: undefined variable: rowstacked
Edit:I have to show data whether intersect each other. Each individual draws line is independent in my scenario. So I've to stick to individual indicator lines. I have to use times and dates over x-axis in line plot mode below.
### plot easy!
reset session
set key left box
set object 1 rectangle from screen 0,0 to screen 1,1 fillcolor rgb"#ffffff" behind
set datafile separator tab
set grid x y my
set xlabel "Setted"
set ylabel "Getted "
set title "Sensor Datas"
set style lines rowstacked title offset 0,-1
set autoscale
#set xtics ("12:00 PM" 0, "6:00 PM" 1, "12:00 PM" 2, "6:00 PM" 4,"12:00 PM" 5, "6:00 PM" 6 )
#plot newlines" \n group 1" , "./Sensor Datas.txt" every ::0::1, \
# newlines "group 2", "./Sensor Datas.txt" every ::2::3
plot "./Sensor Datas.txt" u 2 t "a" w l,\
"./Sensor Datas.txt" u 3 t "b" w l,\
"./Sensor Datas.txt" u 4 t "c" w l,\
"./Sensor Datas.txt" u 5 t "d" w l,\
"./Sensor Datas.txt" u 6 t "e" w l,\
"./Sensor Datas.txt" u 7 t "f" w l,
x
a
b
c
d
e
f
9/24/2022
12:00 PM
68.60
64.30
61.60
54.70
91.40
148.00
6:00 PM
67.08
55.26
66.50
54.05
91.20
152.00
9/25/2022
12:00 PM
70.10
71.60
64.40
59.00
85.60
154.00
6:00 PM
74.40
80.40
67.60
58.80
96.90
156.30
9/26/2022
12:00 PM
66.20
90.60
65.70
55.60
67.90
156.00
6:00 PM
78.80
107.80
66.20
56.10
58.50
153.60

As I understand your question, you have basically two questions:
how to plot a rowstacked line graph? As far as I know there is no dedicated gnuplot plotting style like for histograms. You have to add the values yourself. Check help sum. There is an earlier solution using a recursive function (however, which will be limited to about 250 instances, although enough for most cases).
how to use date/time info from two columns?
Your datafile separator is tab, however, I'm not sure if it is possible to post tab separated code here on SO. Anyway, that's why I've changed it here to comma, but you can easily change it back to tab for your original data.
Furthermore, you are using this very unfortunate 12 h (am/pm) time format. A far as I know, gnuplot can read it as input only from gnuplot 5.4.0 on. For earlier versions you have to use a workaround.
Since you skip the date every second row, you have to memorize it in d0 to plot the values at the right x-(time) position. Furthermore, you create the xticlabel yourself, by a function.
If you don't need the data points as point, simply skip the second part of the plot command.
Check the example below as starting point for further optimization.
Script: (requires gnuplot>=5.4.0, because of %p as time input format)
### rowstacked lineplot with time axis
reset session
$Data <<EOD
, , a, b, c, d, e, f
9/24/2022, 12:00 PM, 68.60, 64.30, 61.60, 54.70, 91.40, 148.00
, 6:00 PM, 67.08, 55.26, 66.50, 54.05, 91.20, 152.00
9/25/2022, 12:00 PM, 70.10, 71.60, 64.40, 59.00, 85.60, 154.00
, 6:00 PM, 74.40, 80.40, 67.60, 58.80, 96.90, 156.30
9/26/2022, 12:00 PM, 66.20, 90.60, 65.70, 55.60, 67.90, 156.00
, 6:00 PM, 78.80, 107.80, 66.20, 56.10, 58.50, 153.60
EOD
N = 8
myDateFmt = "%m/%d/%Y"
myTimeFmt = "%H:%M %p"
set key out box width 1 noautotitle
set datafile separator comma
set grid x y my front
set style fill solid 0.7 border
set tics out
set format x "\n" timedate
myDate(col) = valid(col) ? d0=timecolumn(col,myDateFmt) : d0
myTime(col) = timecolumn(col,myTimeFmt)
mySecs(col1,col2) = myDate(col1) + myTime(col2)
mySum(n) = sum [_i=3:n] column(_i)
myTic(col1,col2) = strftime("%l %p",strptime(myTimeFmt,strcol(col2)))."\n".strcol(col1)
plot for [col=3:N] $Data u (mySecs(1,2)):(mySum(col)):(mySum(col-1)):xtic(myTic(1,2)) \
w filledcurves ti columnhead(col), \
for [col=3:N] $Data u (mySecs(1,2)):(mySum(col)):(mySum(col-1)) skip 1 w lp pt 7 lc col-2
### end of script
Result:
Addition: (line plot without summation)
Script:
In your original script, you were actually plotting column 2, which is the time 12:00 pm and 6:00 pm and missing the 8th column. It seems like your your date and time actually is separated by tab as well, as shown in your table.
### lineplot with time axis
reset session
$Data <<EOD
, , a, b, c, d, e, f
9/24/2022, 12:00 PM, 68.60, 64.30, 61.60, 54.70, 91.40, 148.00
, 6:00 PM, 67.08, 55.26, 66.50, 54.05, 91.20, 152.00
9/25/2022, 12:00 PM, 70.10, 71.60, 64.40, 59.00, 85.60, 154.00
, 6:00 PM, 74.40, 80.40, 67.60, 58.80, 96.90, 156.30
9/26/2022, 12:00 PM, 66.20, 90.60, 65.70, 55.60, 67.90, 156.00
, 6:00 PM, 78.80, 107.80, 66.20, 56.10, 58.50, 153.60
EOD
N = 8
myDateFmt = "%m/%d/%Y"
myTimeFmt = "%H:%M %p"
set key out box width 1 noautotitle
set datafile separator comma
set grid x y my front
set style fill solid 0.7 border
set tics out
set format x "\n" timedate
set yrange [0:]
myDate(col) = valid(col) ? d0=timecolumn(col,myDateFmt) : d0
myTime(col) = timecolumn(col,myTimeFmt)
mySecs(col1,col2) = myDate(col1) + myTime(col2)
mySum(n) = sum [_i=3:n] column(_i)
myTic(col1,col2) = strftime("%l %p",strptime(myTimeFmt,strcol(col2)))."\n".strcol(col1)
plot for [col=3:N] $Data u (mySecs(1,2)):col:xtic(myTic(1,2)) w lp pt 7 lc col-2 ti columnhead(col)
### end of script
Result:

Related

Indicating weekends in timeseries plot and setting xrange in timeseries gnuplot

Using the excellent answer gnuplot - Read Double Quoted datetime stamp I have been able to plot my time series data.
I now trying to indicate weekends (or interesting timeblocks) my plot and set visible xrange to be 31/1 to 28/2
Weekends in Feb this year were 2/5/22 to 2/6/22 and 2/12/22 to 2/13/22 etc - how could I draw a vertical column and shade to indicate weekend or other interesting timeseries blocks? I looked at trying to plot a rectangle using timeseries points, ie weekend1, but I was unable to fill that shape. Then I tried to draw a rectangle, but could not work out how to specify the corners in the timeseries format to display it.
Since my x axis is a timeseries
How could I indicate all weekends in the diagram - kind of like in a calendar or timesheet?
How do I define the xrange to be 1/31/22 to 2/28/22?
reset session
set datafile separator comma
myTimeFmt = "%m/%d/%y, %H:%M %p"
set format x "%d" time
#
# Gives error all points y value undefined!
#
# set xrange ["1/31/22, 12:01 AM":"2/28/22, 11:59 PM"] #
#
# Trying to draw a series to fill to indicate a weekend range - vertically
#
$weekend1 <<EOD
"2/5/22, 12:01 AM",0
"2/5/22, 12:01 AM",600
"2/6/22, 11:59 PM",600
"2/6/22, 11:59 PM",0
EOD
$account <<EOD
"1/31/22, 5:07 PM",1
"1/31/22, 8:01 PM",100
"2/1/22, 11:10 AM",200
"2/6/22, 12:25 PM",300
"2/9/22, 2:02 PM",400
"2/24/22, 4:22 PM",500
EOD
set object 1 rect from 1,1 to 2,2
plot $account u (timecolumn(1,myTimeFmt)):2 w lp pt 1 ps 1 lc "red" lw 1 ti "Account"
#plot $weekend1 u (timecolumn(1,myTimeFmt)):2 w lp pt 1 ps 1 lc "grey"
Here is what I've understood from your question: plot some time series data and highlight the weekends by coloring the background.
One possible way to get this would be to create datablock with all days within your time range and draw boxes (check help boxxyerror) which are colored (check help lc variable) depending of the weekday (check help tm_wday).
first you have to plot the boxes in the background and then the data
the background color should span the whole vertical graph size. For this you need to know the y-range of the data. You can get STATS_min and STATS_max from stats (check help stats).
in order to span the whole graph you can extend the y-range of the boxes (by adding the range again on top and on bottom) but do not apply autoscale for the boxes (check help noautoscale). Autoscale will be only used for the data.
Maybe you have a fixed known y-range, then you can simply set it via set yrange and suitable size of the boxes.
I hope you can adapt the following example to your needs.
Script:
### highlight weekends
reset session
myTimeFmt = "%d.%m.%Y"
DateStart = "01.01.2022"
DateEnd = "28.02.2022"
SecsPerDay = 24*3600
# create some random test data
set print $Data
y=50
do for [t=strptime(myTimeFmt,DateStart):strptime(myTimeFmt,DateEnd):SecsPerDay] {
print sprintf('"%s", %g', strftime(myTimeFmt,t),y=y+rand(0)*10-5)
}
set print
# datablock with every day between start and end date
set print $Days
do for [t=strptime(myTimeFmt,DateStart):strptime(myTimeFmt,DateEnd):SecsPerDay] {
print strftime(myTimeFmt,t)
}
set print
set datafile separator comma
set key noautotitle
set style fill solid 0.4 border
set format x "%d %b\n%Y" timedate
set xtics out scale 2, 1
DayColor(t) = tm_wday(t)==0 ? 0xff0000 : tm_wday(t)==6 ? 0xffdd00 : 0xdddddd
stats $Data u 2 nooutput # get min and max from column 2
plot $Days u (t=timecolumn(1,myTimeFmt)):(0):(t):(t+SecsPerDay):\
(2*STATS_min-STATS_max):(2*STATS_max+STATS_min):(DayColor(t)) w boxxy lc rgb var noautoscale, \
$Data u (timecolumn(1,myTimeFmt)):2 w lp pt 7 lc "black"
### end of code
Result:
NB: first I thought you wanted to plot a calendar highlighting the weekends, but this was not your question. Since I already had the following code (which will plot a calendar in two different versions), I will post it nevertheless. Maybe it is useful to you or others for further adaptions and optimizations.
Script:
### plot a calendar
reset session
myTimeFmt = "%d.%m.%Y"
DateStart = "01.01.2022"
DateEnd = "31.12.2022"
SecsPerDay = 24*3600
set print $Calendar
do for [t=strptime(myTimeFmt,DateStart):strptime(myTimeFmt,DateEnd):SecsPerDay] {
print strftime(myTimeFmt,t)
}
set print
set xrange[0.5:31.5]
set xtics 1 scale 0 offset 0,0.5 font ",8"
set link x2 via x inverse x
set x2tics 1 out scale 0 offset 0,-0.5 font ",8"
set yrange [:] reverse noextend
set ytics 1 scale 0
set key noautotitle
set style fill solid 0.4 border lc "black"
WeekDay(t) = strftime("%a",t)[1:1]
DayColor(t) = tm_wday(t) == 0 ? 0xff0000 : tm_wday(t) == 6 ? 0xffdd00 : 0xdddddd
Month(t) = int(tm_year(t)*12 + tm_mon(t))
MonthLabel(t,y) = strftime( y ? "%B %Y" : "%Y", t) # y=0 only month, y=1 month+year
plot $Calendar u (t=timecolumn(1,myTimeFmt), tm_mday(t)):(Month(t)):(0.5):(0.5):(DayColor(t)): \
xtic(tm_mday(t)):ytic(MonthLabel(t,1)) w boxxy lc rgb var, \
'' u (t=timecolumn(1,myTimeFmt), tm_mday(t)):(Month(t)):(WeekDay(t)) w labels
pause -1
MonthFirst(t) = int(strptime("%Y%m%d",sprintf("%04d%02d01",tm_year(t),tm_mon(t)+1)))
MonthOffset(t) = tm_wday(MonthFirst(t))==0 ? 7 : tm_wday(MonthFirst(t))
set xrange[*:*]
plot $Calendar u (t=timecolumn(1,myTimeFmt), tm_mday(t)+MonthOffset(t)):(Month(t)):(0.5):(0.5):(DayColor(t)): \
xtic(WeekDay(t)):x2tic(WeekDay(t)):ytic(MonthLabel(t,1)) w boxxy lc rgb var, \
'' u (t=timecolumn(1,myTimeFmt), tm_mday(t)+MonthOffset(t)):(Month(t)):(sprintf("%d",tm_mday(t))) w labels font ",8"
### end of script
Result:
Addition: (calendar with events from a datafile/datablock)
Script:
### plot a calendar with events
reset session
myTimeFmt = "%d.%m.%Y"
DateStart = "01.01.2022"
DateEnd = "31.12.2022"
SecsPerDay = 24*3600
set print $Calendar
do for [t=strptime(myTimeFmt,DateStart):strptime(myTimeFmt,DateEnd):SecsPerDay] {
print strftime(myTimeFmt,t)
}
set print
$Events <<EOD
01.01.2022 A 0xff0000
23.04.2022 B 0x00ff00
03.06.2022 C 0x0000ff
12.08.2022 A 0xffff00
05.09.2022 B 0xff00ff
10.10.2022 X 0x00ffff
12.02.2022 Y 0xffa500
EOD
set xrange[0.5:31.5]
set xtics 1 scale 0 offset 0,0.5 font ",8"
set link x2 via x inverse x
set x2tics 1 out scale 0 offset 0,-0.5 font ",8"
set yrange [:] reverse noextend
set ytics 1 scale 0
set key noautotitle
set style fill solid 0.4 border lc "black"
Month(t) = int(tm_year(t)*12 + tm_mon(t))
MonthLabel(t,y) = strftime( y ? "%B %Y" : "%Y", t) # y=0 only month, y=1 month+year
plot $Calendar u (t=timecolumn(1,myTimeFmt), tm_mday(t)):(Month(t)):(0.5):(0.5): \
xtic(tm_mday(t)):ytic(MonthLabel(t,1)) w boxxy lc "light-grey", \
$Events u (t=timecolumn(1,myTimeFmt), tm_mday(t)):(Month(t)):(0.5):(0.5):3 w boxxy lc rgb var, \
'' u (t=timecolumn(1,myTimeFmt), tm_mday(t)):(Month(t)):2 w labels
### end of script
Result:

How to plot week number with string and control xtics increment using Gnuplot?

How do I plot this time samples with a string (W) inside (column 3) ?
And How do I control xtics increment with time format ?
Few lines of Data :
France,FR,2020-W09,118,3318,67012883,4.95128675481698,3.55635925256178,TESSy
France,FR,2020-W10,996,11101,67012883,16.5654714482288,8.97216466984956,TESSy
France,FR,2020-W11,4297,29623,67012883,44.2049329529667,14.5056206326166,TESSy
France,FR,2020-W12,10595,73235,67012883,109.28495644636,14.4671263740015,TESSy
France,FR,2020-W13,24156,122870,67012883,183.35280396756,19.6598030438675,TESSy
France,FR,2020-W14,30304,127029,67012883,189.55907329043,23.8559698966378,TESSy
France,FR,2020-W15,24925,140316,67012883,209.386604065371,17.7634767239659,TESSy
My script :
#https://www.ecdc.europa.eu/en/publications-data/covid-19-testing
#Data (105,77K) here :
system("wget https://opendata.ecdc.europa.eu/covid19/testing/csv -P $PWD -O testing.csv")
reset
set term wxt font ',11' size 1200,800
set datafile separator ","
set grid
#set key at screen 0.9, 0.9
timefmt = "%Y-%s%W"
set xdata time
set xtics format timefmt timedate rotate by -45
SECPERWEEK = 3600.*24.*7.
Y_W(col) = timecolumn(col,timefmt) + SECPERWEEK * (strcol(col)[2:3] - 1)
plot '< grep France testing.csv' u (Y_W(3)):4 notitle w l
Thank you
Here is a suggestion how I would do it. It's maybe not obvious and looks maybe a bit complicated, but it is a gnuplot-only solution.
Since I do not run Linux, I do not have grep, that's why I define myFilter() in gnuplot itself which is platform independent.
Everytime this filter gives a hit, the counter t will be increased by one which has the advantage that the data can contain a interlaced mix of countries. I assume that's what grep would allow as well. The only assumption here is that the week numbers are in (ascending) order, they would not be sorted.
I guess here it is not necessary to have the x-axis as timeformat.
The situation would be different if there are missing calendar week(s) and you want to keep an according gap for them.
With myOffset=0 and myEvery=2 you set how many x-tic labels you want to have displayed.
There is certainly room for improvement and I'm sure there are other solutions... so, just as a starting point...
Code:
### plot filtered data with custom xtics
reset session
$Data <<EOD
France,FR,2020-W09,118,3318,67012883,4.95128675481698,3.55635925256178,TESSy
France,FR,2020-W10,996,11101,67012883,16.5654714482288,8.97216466984956,TESSy
France,FR,2020-W11,4297,29623,67012883,44.2049329529667,14.5056206326166,TESSy
Luxembourg,LU,2020-W11,11,222,33333333,44.4444444444444,55.5555555555555,fghij
Luxembourg,LU,2020-W12,11,222,33333333,44.4444444444444,55.5555555555555,fghij
France,FR,2020-W12,10595,73235,67012883,109.28495644636,14.4671263740015,TESSy
France,FR,2020-W13,24156,122870,67012883,183.35280396756,19.6598030438675,TESSy
Belgium,BE,2020-W13,1111,222222,33333333,444.44444444444,55.5555555555555,abcde
Belgium,BE,2020-W14,1111,222222,33333333,444.44444444444,55.5555555555555,abcde
France,FR,2020-W14,30304,127029,67012883,189.55907329043,23.8559698966378,TESSy
France,FR,2020-W15,24925,140316,67012883,209.386604065371,17.7634767239659,TESSy
EOD
set datafile separator comma
set datafile missing NaN
set xtics rotate by -45
myFilter(dcol,fcol,key) = strcol(fcol) eq key ? (t=t+1, column(dcol)) : NaN
myXtic(col) = sprintf("%s",(t+myOffset)% myEvery ? "" : strcol(col))
myKey = 'France'
myOffset = 0
myEvery = 2
plot t=1 $Data u (t):(myFilter(4,1,myKey)):xtic(myXtic(3)) w lp pt 7 title myKey
### end of code
Result:
The basic error is that the Y_W function is looking in the wrong columns for the week number. It should be substring 7 to 8 not 2 to 3.
Y_W(col) = timecolumn(col,"%Y") + SECPERWEEK * (strcol(col)[7:8])
As explained by theozh in this answer, gnuplot uses American week numbers by default, not ISO 8601, so I have not addressed that here.

GnuPlot plotting time-zero-based data starting with day-zero on the x axis

I have a file of data where the first column is time in seconds. The start of time is 0, and onward from there.
I want to plot the data with an x-axis formatted as days:hours:minutes:seconds. T=0 should map to 00:00:00:00. I can't figure out how to get days to start at 00 instead of 01. I have tried the below. I also tried setting xrange to [-86400:173000], but that maps to day 365, not 0. Shouldn't it be common to plot some time-sampled data, that may span days, starting with T=0?
It seems that GnuPlot needs a different set of time format characters for zero-based time plotting, instead of date-based. Unless it already has it and I have missed it.
data
0 0
3600 10
7200 30
21600 50
160000 100
GnuPlot script
set xdata time
set format x "%02j:%H:%M:%S"
set timefmt "%s"
set xrange [0:173000]
plot "data" using 1:2 with lines
I can get you part way there. Gnuplot has a separate set of time formats for relative time. Zero-based and handles positive and negative intervals. It's hard to find in the documentation, but here is a section from "help time_specifiers".
Format Explanation
%tH +/- hours relative to time=0 (does not wrap at 24)
%tM +/- minutes relative to time=0
%tS +/- seconds associated with previous tH or tM field
Examples of time format:
The date format specifiers encode a time in seconds as a clock time
on a particular day. So hours run only from 0-23, minutes from 0-59,
and negative values correspond to dates prior to the epoch
(1-Jan-1970). In order to report a time value in seconds as some
number of hours/minutes/seconds relative to a time 0, use time
formats %tH %tM %tS. To report a value of -3672.50 seconds
set format x # default date format "12/31/69 \n 22:58"
set format x "%tH:%tM:%tS" # "-01:01:12"
set format x "%.2tH hours" # "-1.02 hours"
set format x "%tM:%.2tS" # "-61:12.50"
Using these relative time formats with your sample data I can get as far as:
$data << EOD
0 0
3600 10
7200 30
21600 50
160000 100
EOD
set xtics time format "%tH:%tM:%tS"
set title 'set xtics time format "%tH:%tM:%tS"'
set xrange [0:173000]
plot $data using 1:2 with lp
Now the problem is that there is no equivalent relative day format. Call that a bug or at least a missing feature. Let's take a stab at adding days to the format by hand.
secperday = 3600*24
days(t) = gprintf("%02g:", int(t)/secperday)
hours(t) = strftime("%02tH:%tM:%tS", int(t)%secperday)
# Create ten days worth of tic labels
# Every six hours with no label; once a day with full label
set xtics 6*3600 format ""
do for [i=0:10] {
T = day * secperday
set xtics add ( days(T).hours(T) T )
}
plot $data using 1:2 with lp
As mentioned in the comments above, one workaround would be using week days, which however would limit you to 7 days.
Since 0 seconds correspond to Thursday, 01.01.1970 00:00:00 you have to subtract 4 days = 24*3600*4 seconds to make it a Sunday (=0).
Another strange workaround would be to use multiplot and plot twice, just for the day labels. You have to set a bottom margin to exactly "overplot" the previous plot. There would be still room for fine tuning.
By the way: If the scale is several days then the question is if seconds in the label are actually relevant?
Code:
### timedate days starting from zero
reset session
$Data <<EOD
0 0
3600 10
7200 30
21600 50
160000 100
450000 222
500000 333
EOD
set multiplot layout 2,1
# first workaround, limited to 7 days
set format x "day %1w\n%H:%M:%S" timedate
plot $Data u ($1-24*3600*4):2 w lp pt 7 notitle
# second workaround, using multiplot
set format x "\n%H:%M:%S" timedate
set bmargin 3
plot $Data u 1:2 w lp pt 7 notitle
set multiplot previous
set format x "day %s"
set xrange[GPVAL_X_MIN/86400:GPVAL_X_MAX/86400]
plot $Data u ($1/86400):2 w p ps 0 notitle # point size zero, i.e. invisible
unset multiplot
### end of code
Result:

Gnuplot time range limit

$data << EOD
1563619139 10
1532083139 9
1500547139 8
1469011139 7
1437388739 6
1405852739 5
1374316739 4
1342780739 3
1311158339 2
1279622339 1
EOD
set terminal png
set xdata time
set timefmt "%s"
set format x '%Y'
unset key
plot '$data' u 1:2
How do I plot values only from say 2015? I tried plot ["2015":] '$data' u 1:2 via the docs but it doesn't work as expected.
I realise I could edit $data, but I don't want to do that.
There is an older an a newer gnuplot syntax for timedata.
The example below uses the newer syntax.
Check help time/date, help timecolumn, and help strptime.
Code:
### time data
reset session
$Data << EOD
1563619139 10
1532083139 9
1500547139 8
1469011139 7
1437388739 6
1405852739 5
1374316739 4
1342780739 3
1311158339 2
1279622339 1
EOD
unset key
set format x "%Y" time
StartTime = strptime("%Y","2015") # 2015-01-01 00:00:00 in seconds after 1970
set xrange[StartTime:]
set xtics StartTime, 3600*24*365 # start time and major tic distance one year in seconds
plot $Data u (timecolumn(1,"%s")):2 w lp pt 7
### end of code
Result:
You must use the same format of timefmt to specify the range.
plot ["1420092000":] '$data' u 1:2
The seconds in Gnuplot are measured starting from 1970.
I calculated the starting time considering 365.25 days in a year, hence 1420092000 s, but using strptime("%Y","2015"), as reported in the other answer, is without doubt more correct and precise.
You can add
set xtics 31557600
to have only major tics corresponding to the beginning of year. The value specified is the time increment between tics that must be given in seconds.

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:
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.

Resources