Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore points with y=0

Tags:

gnuplot

I am plotting a graph and I would like to omit all points that have y=0. I don't know a priori at which lines these results appear, so I can't tell gnuplot to use just some lines.

Is that possible or do I have to edit my data set (and replace y=0 for somewhere outside my range)?

like image 227
iomartin Avatar asked Aug 08 '12 13:08

iomartin


2 Answers

The elegant way to do that is using:

set datafile missing

For example, you can do:

set datafile missing '0'

and gnuplot will skip the entries with the 0 symbol. You can use strings as well as NaN or 0.000.

like image 196
Pato Sandaña Avatar answered Sep 19 '22 23:09

Pato Sandaña


You can do this pretty easily:

plot "mydataset.dat" u 1:($2 == 0 ? NaN : $2)

Here we use the gnuplot ternary operator to replace values of 0 with NaN. Gnuplot silently ignores NaN, so that should work just fine.

like image 43
mgilson Avatar answered Sep 20 '22 23:09

mgilson