In gnuplot, with no "set datafile", how to ignore "nan" and "-nan"?

The gnuplot set datafile missing "nan" command tells gnuplot to ignore nan data values ​​in the data file.

How to ignore both nan and -nan ? I tried the following in gnuplot, but the effect of the first statement is overwritten by the following.

 gnuplot> set datafile missing "-nan" gnuplot> set datafile missing "nan" 

Is it possible to somehow embed a grep -v nan in a gnuplot command or even some regular expression to exclude any conceivable non-numeric data?

+4
source share
1 answer

It is not possible to use regexp to set datafile missing , but you can use any program to filter your data before plotting and replacing the regular expression with one character, for example. ? that you set to mark the missing data point.

Here is an example that does what you originally requested: filtering -nan , inf , etc. For testing, I used the following data file:

 1 0 2 nan 3 -inf 4 2 5 -NaN 6 1 

And the script drawing might look like this:

 filter = 'sed -e "s/-\?\(nan\|inf\)/?/ig"' set datafile missing "?" set offset 0.5,0.5,0.5,0.5 plot '< '.filter.' data.txt' with linespoints ps 2 notitle 

This gives the following result:

enter image description here

Thus, the plot command skips all missing data points. Can you refine the sed filter to replace any non-numerical values ​​with ? if this option is not enough.

This works fine, but only columns can be selected, for example. with using 1:2 , but does not perform calculations on columns, for example, for example. using ($1*0.1):2 . To allow this, you can filter out any line containing nan , -inf , etc. Using grep , as done in gnuplot, without expression-evaluated data (thanks @Thiru for the link):

 filter = 'grep -vi -- "-\?\(nan\|inf\)"' set offset 0.5,0.5,0.5,0.5 plot '< '.filter.' data.txt' with linespoints ps 2 notitle 
+5
source

Source: https://habr.com/ru/post/1501460/


All Articles