I'm having trouble getting a "time friendly" X-axis layout in Gnuplot.
I need to present some data referring to a period within one day; the time X data is represented in decimal form, e.g. X=20.75 meaning 20 hours and 45 mins, the range is generally [0 : 24], but normally a subset, such as [2.25 : 8.75].
The default Gnuplot x-axis layout will be something like the range [0 : 25] with major tics at 0,5,10,15,..., which is nice for normal decimal data, but I would like it to choose something more "time friendly" in the usual clock manner, I mean major ticks at hours 1,2,3 or 6 and minor ticks at 1,5,15 or 30 minutes, suitably chosen depending on the range.
Does anybody know how to do that?
How about this?
set xtics 1, 0.25
Unfortunately, according to the manual:
Minor tics can be used only with uniformly spaced major tics. Since major tics can be placed arbitrarily by
set {x|x2|y|y2|z}tics
, minor tics cannot be used if major tics are explicitlyset
.
Using gnuplot 4.6 patchlevel 0
I ended up with this shell script that can be called followed by the desired output name:
save this as makeChart.sh
path='/home/you/yourdir/dat2.txt'
echo "
set terminal unknown
plot '$path' u 1:2
min = (GPVAL_Y_MIN-1)
max = (GPVAL_Y_MAX+1)
set terminal pngcairo size 1400,600 enhanced font 'Helvetica,12'
set timefmt '%H:%M'
set ylabel 'Temperature'
set xlabel 'Time'
unset key
set grid
set title 'Temperature Sensor 1'
set xtics rotate right
set xtics 0,1800,96000
set xdata time
set mxtics 2
set format x '%H:%M'
set format y '%.2f'
set yrange [min:max]
set output '/var/www/somefolder/$1'
plot '$path' u 1:2 index 0 with lines" | gnuplot
Some sample data from dat2.txt:
A temperature reading every 5 minutes over one day.
00:05 74.75
00:10 74.85
00:15 74.85
.
.
.
23:30 75.65
23:35 75.65
23:40 75.52
23:45 75.65
23:50 75.65
23:55 75.75
run it like this:
you@yourpc $sudo ./makeChart.sh chartx.png
Kept playing with the xtics range until I had 30 minute intervals.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With