N. Hof
N. Hof

Reputation: 31

Gnuplot-- adding too much data to xaxis

I've got a file that is "date,time,temperature" new line "date,time,temperature" etc

Example:

12/01/19,23:30:13,74.23
12/01/19,23:45:13,74.33


12/02/19,00:00:13,74.20
12/02/19,00:15:13,74.06

And am looking to Graph it using Gnuplot.

The graphing portion comes out just fine, and for the most part it looks like it will do the trick for what i need.

However, the xtics are adding additional information that i did not set for them to have and have no idea where it's coming from.

Code:

set terminal gif animate delay 200
set output "path/to/file.gif"
set datafile separator ","
set title 'Temperature in Aquarium"
set key bottom left box
set key width 1
stats "path/to/file.csv" using 2:3 name "A"
set xlabel 'Time'
set xdata time
set timefmt '%H:%M'
set xtics 14400
set ylabel 'Temp(F)'
set yrange [68:80]
set style data lines
do for [i=0:int(A_blocks-1)] { plot 'path/to/file.csv' using 2:3 index i title "Dec " .(i+1)

What i'm expecting to see in the x-axis is simply "00:00, 04:00, 08:00, 12:00, 16:00, 20:00, 00:00"

And i do see that for any data gathered from Today. but any data that is gathered from a previous day looks like:

"01/01 00:00, 01/01/ 04:00, 01/01 08:00, 01/01 12:00"...

And each day after repeats that for the x-axis, until it gets to Todays data and then it shows me the "00:00, 04:00, 08:00..."

So how can I get it so it doesn't show me the "01/01" on all previous days?

Upvotes: 0

Views: 171

Answers (1)

theozh
theozh

Reputation: 26023

Completely revised code. I guess you haven't set the format for the x axis, e.g. set format x "%H:%M". I thought set xdata time is somewhat "outdated", instead use set format x "%H:%M" timedate and as you might know, time is handled as seconds from 01/01/1970.

Here a possible starting point for further tweaking.

Code:

### animated time data
reset session
set term gif size 480,320 animate delay 100
set output "Animation.gif"
set datafile separator ","
myTimeFmt = '%m/%d/%y,%H:%M:%S'

# generate some test data
StartDateTime = strptime(myTimeFmt, "12/18/19,00:00:00")
set print $Data
    do for [day=0:7] {
        do for [i=0:24*4-1] {
             print strftime(myTimeFmt,StartDateTime+day*24*3600 + i*15*60). \
             ",".sprintf("%.1f",74+6*sin(i/12.)+rand(0)*3)
        }
        if (day<7) { print ""; print ""}   # 2 empty lines at the end of the day
    }
set print

set timefmt myTimeFmt
set format x "%H:%M" timedate
set xtics 4*3600
stats $Data u 0 nooutput
set key top center

do for [i=0:STATS_blocks-1] {
    plot $Data u (timecolumn(1,myTimeFmt)):3 index i w lp pt 7 ti strftime("%b %d", StartDateTime+i*24*3600)
}
set output
### end of code

Result:

enter image description here

Upvotes: 1

Related Questions