8
votes

Example:

enter image description here

I want to plot a chart just like above one: a line with some missing data points, that means the line is discontinuous.

How can I do this?

2

2 Answers

10
votes

This depends on what your datafile looks like. If you insert a blank space in your datafile, it won't connect those adjacent points (This is the easiest way):

consider:

 #datafile
 1 2
 2 3

 4 2
 5 3

and then the script to plot it:

 plot 'datafile' u 1:2 w linespoints

There are other tricks you can play with missing data: set datafile missing. A good reference for this is the builtin help (help missing).

0
votes

For a single plot, use set datafile missing to specify the character string that signifies a missing value, and the using $ specifier to ensure that gnuplot leaves a gap in the line for a missing value. The different using specifiers are described in the gnuplot documentation for set datafile missing.

Where the column number is specified as a variable, this is a bit trickier. For example, to plot multiple columns of a file one could specify the column number using a variable:

do for [i=2:10] {
    plot 'datafile' using ($1):i with lines
}

However, if we try to use the $ syntax it doesn't work:

do for [i=2:10] {
    plot 'datafile' using ($1):($i) # ERROR!
}

The solution is to use the column function, which also leaves blanks for missing values:

do for [i=2:10] {
    plot 'datafile' using ($1):(column(i)) with lines
}