2022-05-29

Changing x axis scale on the fly

I am using the following gnuplot script to plot data from a set of files that are being added to constantly, once every five minutes:

set terminal x11 size 1900, 900
# The plot will not jump to the current window on update.
set term x11 1 noraise
set obj 1 rectangle behind from screen 0,0 to screen 1,1
set obj 1 fillstyle solid 1.0 fillcolor rgbcolor "black"
set grid lc rgb "white"

set key left top
set key textcolor rgb "white"

set border lc rgb "white"

set xtics textcolor rgb "white"
set xtics font "Times,12"
set xtics 1
set xlabel "Hours" textcolor rgb "white"

set ytics textcolor rgb "white"
set ytics font "Times,12"
set ytics 5
set ylabel "Hits" textcolor rgb "white"

set yrange [0:50]
set y2tics font "Times,10"
set y2tics 1                  # Figures on the right side of the plot as well
set y2range [0:50]

plot "/tmp/Stats/One" using ($1)/(12.):2 title "One" with lines, "/tmp/Stats/Two" using ($1)/(12.):2 title "Two" with lines, "/tmp/Stats/Three" using ($1)/(12.):2 title "Three" with lines
pause 300
reread

The tics in the x axis correspond to hourly intervals. This works fine, until the script has been running for a day or so - at which point the tics in the x axis start to look a bit cluttered.

Would it be possible to change this dynamically from within the gnuplot script itself? The idea is that if the script has been running for more than, say, half a day, the tics in the x axis should be present once every two hours, rather than once every hour. And possibly other similar changes later on - e.g. after one week, there should be one tic per day. The text label would have to change consequently.

Is gnuplot capable of this, or are we talking about a shell script-driven approach instead? The latter is obviously possible, but it would be more cumbersome.



No comments:

Post a Comment