Search code examples
plotgnuplotzero

Is it possible to suppress plotting zero values from datafile column?


I wrote same data collecting procedure, and over time I added more columns to the data output. To build a consistent format, the procedure outputs 0 where no measurements were available.

I wonder when plotting the data file whether it is possible not to plot zero values (like if no data were present). Some of the new columns are plotted by themselves (using 2:7) and others are used in an expression (using 2:($7+$8)).


Solution

  • Here is another option: set datafile missing "0". Note, that a value of 0.0 will be plotted. This will also plot the lines connected in case you use with lines or with linespoints

    Code:

    ### do not plot values "0"
    reset session
    
    $Data <<EOD
    1  1.1
    2  0
    3  5.1
    4  2.1
    5  0
    6  0.0
    7  5.1
    EOD
    
    set datafile missing "0"
    
    plot $Data u 1:2 w lp pt 7, \
         '' u 1:($1+$2) w lp pt 7
    ### end of code
    

    Result:

    Example Output

    Also check help set datafile, help set datafile missing or help missing.