0

The question was somewhat generic but it could be used in many ways. We all use GNUplot to plot data over the samples recorded in a file.

There is a data logger that records a measurement once per second. ( So a file that is an hour long has 3600 lines, a 24 hour file has 86400 lines, may be of any length ) If that was to be plotted it would be the y variable over the samples. But how can I get the data to show the y variable over minutes ( ex samples/60 ) or hours ( samples/3600)?

If some math is involved obviously the minutes or hours would have to be a float which is not a big deal. I do not need genuine time in the X-axis ( that would be cool to know how to do too ). I need to show the 86,400 samples of the 24 hour log to be from 0 to 24 in the X-axis.

This is not necessarily only applicable to time. Perhaps someone wants every 1000 samples to be marked as per km, 5280 samples to be a mile or 1024 samples to be marked in a computer type label.

Thanks.

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • Does the data log the sample and time? Use the time as X. If not create an array with the starting time, if known, else 0. add 1 (sec) for each data point. Use this for X. – cliff2310 Aug 12 '22 at 22:47
  • Welcome to StackOverflow! For gnuplot questions, please always show a few lines of example data and if you have some (non-working) script and ideally the graph output (or handsketch what the graph should be). – theozh Aug 13 '22 at 06:06

2 Answers2

0

In the specific case of time/date data gnuplot offers a command to treat input coordinates for a specific axis as a time measured in seconds. The most common case is time data along the x axis, for which you could specify something like

set xdata time
set timefmt "%Y-%m-%d"          # Data read from the file looks like "2022-01-31"
set xtics time format "%d %b"   # tics along x will look like "21 Jan"

The point is that even when you are using time-based commands, the raw numbers stored as coordinates are always in seconds. If you want to read in raw seconds, omit the set xdata time command. The output formatting of the xaxis tic labels can still be in time units. Conversely if for some reason you want to read data from a file that contains units of days/hours/etc but display them as seconds, you can keep the set xdata time but change to set xtics numeric.

Although it is less common, the equivalent commands (set ydata, set ytics time format, ...) work for other axes also. So you could have dates along y or x2, and so on.

As to your other specific examples, gnuplot provides formatting options for quantities in scientific notion and in computer-style units like 1024 bytes = 1 kibyte.

For a more detailed list of format options, see the documentation section format specifiers. Below is a table from that section (there is a separate documentation for time/date)

 The acceptable formats (if not in time/date mode) are:

       Format       Explanation
       %f           floating point notation
       %e or %E     exponential notation; an "e" or "E" before the power
       %g or %G     the shorter of %e (or %E) and %f
       %h or %H     like %g with "x10^{%S}" or "*10^{%S}" instead of "e%S"
       %x or %X     hex
       %o or %O     octal
       %t           mantissa to base 10
       %l           mantissa to base of current logscale
       %s           mantissa to base of current logscale; scientific power
       %T           power to base 10
       %L           power to base of current logscale
       %S           scientific power
       %c           character replacement for scientific power
       %b           mantissa of ISO/IEC 80000 notation (ki, Mi, Gi, Ti, Pi, Ei, Zi, Yi)
       %B           prefix of ISO/IEC 80000 notation (ki, Mi, Gi, Ti, Pi, Ei, Zi, Yi)
       %P           multiple of pi

If you are having a specific problem with any of this, please modify your question to provide a few lines of data showing the format used, and a more complete description or sample of what you want the output to look like.

Ethan
  • 13,715
  • 2
  • 12
  • 21
0

This question popped up again because of a tag-edit. Apparently, there doesn't seem to be any interest in an answer by the OP, because there is no feedback at all. Nevertheless, let me give answer for what I've understood from the question and maybe it is helpful to others.

There is the pseudocolumn 0 which is basically the line index starting from 0. For details check help pseudocolumns.

If you have only y-data e.g. like:

# y1   y2    y3    y4
 1.1   1.2   1.3   1.4
 2.1   2.2   2.3   2.4
 3.1   3.2   3.3   3.4
 4.1   4.2   4.3   4.4
 5.1   5.2   5.3   5.4
 6.1   6.2   6.3   6.4

So, you are missing the x-coordinate for plotting. Simply, multiply or divide the row-number, i.e. pseudocolumn 0 with a suitable factor.

Attention: keep in mind that gnuplot by default will do integer division, i.e. 1/2=0. In order to force floating point division you could write 1/2. or 1./2 and for variables of which you are not sure whether they are integer or floating point you can write real(N)/M or N/real(M), (check help real). However, since $0 (and all other columns) are always returned as floating point number there is no issue here. In order to be sure always write 60., 3600., 1000., 1024., 5280..

plot "myFile.dat" u ($0/60):2        # 1 line/second --> x-axis in minutes
plot "myFile.dat" u ($0/3600):2      # 1 line/second --> x-axis in hours
plot "myFile.dat" u ($0/1000):2      # 1 line/meter  --> x-axis in kilometers
plot "myFile.dat" u ($0/1024**2):2   # 1 line/byte   --> x-axis in MiB (mebibytes not megabytes!)
plot "myFile.dat" u ($0/5280):2      # 1 line/foot   --> x-axis in miles
theozh
  • 22,244
  • 5
  • 28
  • 72