If you want to neglect the weekends on the time scale you can simply define a function which returns the day number after time(0)
omitting the weekends. Note, that time(0)
is 1970-01-01 00:00:00
for gnuplot 5.x and 2000-01-01 00:00:00
for gnuplot 4.x.
dw5(t)
returns day number after time(0)
omitting the weekends and NaN
if t
is a weekend day.
dw5tow7(n)
returns the date from the "5-day-week" day number and NaN
if input is NaN
.
dw7Tic(n)
returns the date label for xtic and empty string ''
if input is NaN
.
For example, the command:
do for [i=0:10] { print sprintf("%s % 4d",strftime("%Y-%m-%d",dw5tow7(i)),i) }
will return in gnuplot5.x:
1970-01-01 0
1970-01-02 1
1970-01-05 2
1970-01-06 3
1970-01-07 4
1970-01-08 5
1970-01-09 6
1970-01-12 7
1970-01-13 8
1970-01-14 9
1970-01-15 10
Script: (works for gnuplot>=5.0.0, Jan. 2015)
### remove weekends on time scale
reset
FILE = "SO9680677.dat"
# create some random test data
set print FILE
t0 = time(0)
y0 = 100
do for [i=0:60] {
t = t0 + i*3600*24
if (int(tm_wday(t)+1)%7>1) {
print sprintf("%s %g",strftime("%Y-%m-%d",t),y0=y0+rand(0)*1-0.5)
}
}
set print
SecPerDay = 3600*24
SecPerWeek = 7*SecPerDay
isWeekend(t) = int(tm_wday(t)+1)%7 < 2
myTimeFmt = "%Y\n%m-%d"
tOff = tm_year(0)==1970 ? 3 : 5 # offset gnuplot5.x: 3, gnuplot4.x: 5
dw5(t) = isWeekend(t) ? NaN : int(t/SecPerDay) - 2*int((t+tOff*SecPerDay)/SecPerWeek)
dw5tow7(n) = n==n ? n*SecPerDay + (int(n+tOff)/5)*2*SecPerDay : NaN
dw7Tic(n) = n==n ? strftime(myTimeFmt,dw5tow7(n)) : ''
set key top center out noautotitle
set grid x,y
set ytics 1
set multiplot layout 2,1
set xrange[:] noextend
set format x myTimeFmt timedate
plot FILE u (timecolumn(1,"%Y-%m-%d")):2 w lp pt 7 lc rgb "red" ti "with weekends"
set format x "%g\n" numeric
plot FILE u (dw5(timecolumn(1,"%Y-%m-%d"))):2 w lp pt 7 lc rgb "web-green" ti "without weekends", \
'' u (t0=dw5(timecolumn(1,"%Y-%m-%d"))):(NaN):xtic(dw7Tic(t0)) every 5
unset multiplot
### end of script
Replace the above multiplot section with the snippet below and the script will run with gnuplot>=4.6.0 (March 2012). Maybe with further tweaking it can be made work with gnuplot 4.4.0.
### version for gnuplot 4.6.0, March 2012
set multiplot layout 2,1
set timefmt "%Y-%m-%d"
set xdata time
set format x myTimeFmt
plot FILE u 1:2 w lp pt 7 lc rgb "red" ti "with weekeends"
set format x "%g\n"
plot FILE u (dw5(timecolumn(1))):2 w lp pt 7 lc rgb "web-green" ti "without weekends", \
'' u (t0=dw5(timecolumn(1))):(NaN):xtic(dw7Tic(t0)) every 5 w p
unset multiplot
Result:
Actually, after all, the larger your time range the less you will notice if there are weekends or not.
