3

Version: gnuplot v5.3.0

Context

I am trying to plot the following CSV data, where the first column is a UNIX timestamps in milliseconds with floating point notation, the second one an integer representing an instant throughput (in units/s).

...
1.6069112402441587e+12,334
1.606911240244567e+12,335
1.6069112402475227e+12,336
1.6069112402481619e+12,337
...

For this, I wrote the following script file:

set xdata time
set timefmt "%s"

set datafile separator comma

plot "results.csv" u 1:3

My understanding from the gnuplot V5 documentation is that the millisecond precision is supported in this version:

The current version of gnuplot stores time to a millisecond precision.

Problem

Upon execution of the plot command, gnuplot throws the following warning for every data entry in the CSV file, and doesn't plot any value:

"throughput.plt", line 15: warning: time value out of range

What I tried

I converted all entries from the first column of the data file to UNIX timestamps in seconds (changed e+12 to e+9). This time plot executes without any error, but the loss of precision makes the graph too approximate to be analyzed.

Is there a way in gnuplot to ingest UNIX timestamps in milliseconds?

2
  • What about subtracting the first value from all values? e.g. 1.6069112402441587e+12. I don't assume you want to display measurement data over several days with millisecond precision...
    – theozh
    Dec 2, 2020 at 17:02
  • Not over several days, but between 1-30 minutes depending the load test that's being performed. Dec 2, 2020 at 17:57

2 Answers 2

2

If the column represents time is already expressed as a real number in UNIX time, set timefmt "%s" is not necessary. It is sufficient to read the numbers as they are.

However, the number '1.6069112402441587e+12' in your data is interpreted as UNIX time "52890/12/27 17:24:04 +0000". So you will get the message "warning: time value out of range". This is not the time you intended, of course.

If you were to use your data as it is, the script would look something like this.

set xdata time

# set timefmt "%s"    ### This line is not needed!

set datafile separator comma

set format x "%H:%M\n%.4S"
set grid xtics

plot "results.csv" u ($1/1000):2 w linespoints

enter image description here

1
  • Exactly the result I expected to see. I was pretty close with my conversion from e+12 to e+9, turns out I didn't lose any precision. Dec 2, 2020 at 20:38
2

Subtract the first value from all values. Something like this. You could also use the pseudocolumn $0 for this.

Code: (edit: I prefer to have copy&paste examples, including data)

### normalize time data relative to start time
reset session

# create some random test data
set print $Data
x = 1.6069112402441587e+12
y = 333
do for [i=1:10000] {
    print sprintf("%.16f, %d",x=x+rand(0)*10, y=y+int(rand(0)*15)-7)
}
set print

set datafile separator comma
set key top left
set xlabel "relative time in seconds"

plot t=0 $Data u ((t==0 ? (t0=$1, t=1) : NaN), ($1-t0)/1000 ):2 w l title "relative time"
### end of code

Result:

enter image description here

2
  • That's a very neat trick I took note of. My alternative was to display raw timestamps with set format x "%.0f" and show a tick every 10s with set xtics 10000. How would you display ticks in seconds using those generated x values? Dec 2, 2020 at 18:18
  • 1
    for example divide by 1000, i.e. replace $1-t0 by ($1-t0)/1000, or for minutes ($1-t0)/60000, etc.
    – theozh
    Dec 2, 2020 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.