newspaint

Documenting Problems That Were Difficult To Find The Answer To

Millisecond Time Resolution X/Y Scatter Plotting With Gnuplot

So you have timestamps with a resolution of milliseconds and you want to plot them on a X/Y scatter graph using Gnuplot.

This is possible because the %S specifier in timefmt accepts a double (i.e. a floating point value) so that the fractional portion of the time will be interpreted as a fraction of seconds.

You can print fractional seconds on the X-axis using the set format x “%H:%M:%.3S” command.

Here is a Gnuplot plot file to demonstrate this:

set terminal png size 400,320 font 'Verdana,8'
set output 'test.png'
set datafile separator ","
set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"
set format x "%H:%M:%.3S"
set title 'Speed over Time'
set xlabel "Timestamp"
set ylabel "km/h"
set xrange ["2013-09-16 10:59:05.000":"2013-09-16 10:59:06.000"]
set yrange [0:12]
set xtics out rotate by -80
set key below
set pointsize 1.0

plot '-' using 1:2 title 'My Car' with points pointtype 2
        2013-09-16 10:59:05.040,5
        2013-09-16 10:59:05.240,7
        2013-09-16 10:59:05.470,10
        2013-09-16 10:59:05.780,3
        e

If you run this you should get the following image created:

Gnuplot 4.6 Millisecond Resolution Scatter Plot

Gnuplot 4.6 Millisecond Resolution Scatter Plot

The documentation for Gnuplot is available at the Gnuplot documentation home page. Note that you might need a recent version of Gnuplot to achieve millisecond-resolution plotting as it appears this was introduced into version 4.6.

One response to “Millisecond Time Resolution X/Y Scatter Plotting With Gnuplot

  1. Terry Ledford June 17, 2015 at 6:55 pm

    This is exactly what I am looking for, I thank you for this help.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: