|
From: Ethan M. <eam...@gm...> - 2021-03-15 22:10:23
|
On Monday, 15 March 2021 13:20:14 PDT Roderick Stewart wrote:
> I’m new to gnuplot (love it!) but can’t work out how to plot time series data from a file when the file contains no time information, just equally-spaced data values.
>
> I have a binary file which has one year’s worth of data at 1-minute intervals.
>
> I can plot it using:
>
> plot ‘2021.dat’ binary format=“%int32” using 0:1
>
> But I want the X axis to be a date axis so I can, for example, set xrange.
>
> How do I get the timestamps into the plot?
The units of time in gnuplot are seconds.
A date corresponds to the number of seconds elapsed since the start of the
epoch (1 Jan 1970).
Each record in your data adds 60 seconds to the date.
So the task is
1) Determine the canonical date (number of seconds since 1970) of the start time.
2) Add 60 seconds for each data point
Suppose your data starts with the first minute of 2021.
timefmt = "%d-%b-%Y"
time0 = strptime( timefmt, "01-Jan-2021" )
# the xrange and tic placement will use the timefmt we just set
set xdata time
set xrange [time0 : *]
set xtics ("01-Jan-2021", "01-Feb-2021", "01-Mar-2021")
# the actual tic labels will only use the month name
set xtics format "%b" # Only the month names
plot '2021.dat' binary format=%int32" using (time0 + $0 * 60.) : 1 with lines
Ethan
>
> Thanks in advance.
> Roderick Stewart
|