Join data points with non-continuous lines

If you have measurement data and like to plot them as points combined by lines, you will probably do that with the linespoints plotting style. But for some applications it is required to combine the data points by non-continuous lines to emphasize that the data came from measurements as shown in Fig. 1.


Plotting data

Fig. 1 Plot of the data from plotting_data1.dat with non-coninuous lines between its points (code to produce this figure)

In Gnuplot exists no line style that can do this directly. But with a little trick it is very easy to achieve. Since Gnuplot 4.4. there exists the property pointinterval (see the documentation) in combination with the plotting style linespoints. This property plots not every single point, but only every second for a value of 2 and so on. But if we use the value -1 it tells Gnuplot to insert a little gap between the points and the line. The only problem is that the size of this gap is not scalable. But by using two different line styles this is also achievable.

set style line 1 lc rgb '#0060ad' lt 1 lw 2 pt 0 pi -1 ps 3
set style line 2 lc rgb '#0060ad' lt 1 lw 2 pt 7 ps 1.5

In the first line style we specify a point interval pi of -1 and enlarge the gap by using a point size of 3. With the point size value we can easily define any gap size we need. The other trick is to use point type 0 that is a point of size 0 independent of the given pointsize. In the second line style we specify the real point we want to plot using with points. Finally our plot command looks now like the following.

plot 'plotting_data1.dat' with linespoints ls 1, \
     ''                   with points ls 2

Using the same data as in the first plot of the introduction chapter Plotting data we will get Fig. 1 as a result.

Tags: , ,

  1. Luke’s avatar

    Looks good. An advice for reproducing this style in the key?

  2. James’s avatar

    Hi Luke,

    I was also wondering about that. Turns out you can do:

    set key spacing -1
    plot ‘plotting_data1.dat’ with linespoints ls 1 title “title for the key”, \
    ” with points ls 2 title ” ”

    If you give a plot a blank title it won’t show up in the key, but if you give it a title that’s a single space character it’ll show up. Setting the key spacing to -1 will overlay the two key entries, which will achieve what we want. This will only work for a single key entry, and for a vertically spaced key (though there’s no difference between horizontal and vertical spacing with a single entry).