简体   繁体   中英

How to plot line with missing data points in gnuplot

Example:

在此输入图像描述

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?

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 ).

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM