gnuplot - Begin a plot on a specific day of the week -
i'm learning gnuplot working on tidal data, in monthly files, in format:
2011/03/01 tue 08:42 9.39 h 2011/03/01 tue 15:04 0.2 l 2011/03/01 tue 21:18 8.67 h 2011/03/02 wed 03:16 0.71 l 2011/03/02 wed 09:31 9.51 h 2011/03/02 wed 15:49 0.09 l 2011/03/02 wed 22:01 8.91 h 2011/03/03 thu 04:01 0.48 l 2011/03/03 thu 10:14 9.58 h 2011/03/03 thu 16:28 0.05 l 2011/03/03 thu 22:39 9.11 h
all far: can output stacked plots pdf multiplot layout setup, i'd have weekly plots run monday-sunday.
with fractional weeks, first week, how can this? can set xrange manually, need re-done each weekly plot command.
what i'd figure out 2 things:
- a way handle first week problem;
- a way automate xrange each succeeding week (i.e., have gnuplot parse timestamp , start new plot each monday? can perhaps using ternary operator?)
setup:
gnuplot: version 4.4 patchlevel 2
osx 10.6.6
setup & plot commands:
set timefmt "%y/%m/%d-%h:%m" set origin 0,0 set xdata time unset key set samples 1000 mydate(col1,col3)=sprintf("%s-%s",strcol(1),strcol(3)) set grid noxtics set xtics nomirror font "arial,10" tc rgb "blue" set xtics offset 0,0 # required position of tic labels when stacked. set yrange [-3:13] set ytics 3 set grid ytics set x2data time set x2tics 86400 set grid x2tics set x2tics 86400 set format x2 "%d" # displays number of day of month set x2tics offset 3.5,-3 font "helvetica,20" # required position of numbers when stacked. #### set size 1,.2 # un-comment setting stacked layout. set tmargin 3 # gives adequate room between each row of days + labels. set lmargin 5 set bmargin 2 set rmargin 2 plot 'monthlytidedatamarch.txt' u (mydate(1,3)):4:xticlabels(strcol(4) . " \n" . strcol(3) ) lc rgb "green" lw 3 sm cspl notitle
i use bash script , use "date" program. probable need tweak date formats, etc., in principle;) should work...
# write dates temporary file, create date range # each line in input file echo -n ""> tmp.out while read line; d=${line:0:22} y=$(date --date "$d" +%y) w=$(date --date "$d" +%w) m=$(date --date "$y-01-01 +$w weeks -1 week +2 day" +%y-%m-%d) s=$(date --date "$y-01-01 +$w weeks -1 week +8 day" +%y-%m-%d) echo '"'$m'":"'$s'"' >> tmp.out done < data.txt # make them unique uniq tmp.out > dates.out # create gnuplot input file, needs code above cat <<eof > in.gnu reset eof # add plot command each date range. # needs plot command , perhaps more plot specific data (title, etc.) while read line; cat <<eof >>in.gnu set xrange [$line] plot "data.txt" u 1:2 eof done < dates.out
the script generates gnuplot input file can run on data.
Comments
Post a Comment