Re: plotting time series data

Ethan Merritt <[email protected]>
Newsgroups gmane.comp.graphics.gnuplot.user
Message-ID <1771756.9fzjmPIryH@stonelion>
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





_______________________________________________
gnuplot-info mailing list
[email protected]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.