gnuplot 命令 set datafile missing "nan"
告诉 gnuplot 忽略 nan
数据文件中的数据值。
如何忽略两者 nan
和 -nan
?我在 gnuplot 中尝试了以下内容,但是第一个语句的效果被下一个覆盖了。
gnuplot> set datafile missing "-nan"
gnuplot> set datafile missing "nan"
是否可以以某种方式嵌入
grep -v nan
在 gnuplot 命令中,甚至是某种正则表达式来排除任何可以想象的非数字数据?
最佳答案
不能为 set datafile missing
使用正则表达式,但您可以使用任何程序在绘图之前过滤数据,并用一个字符替换正则表达式,例如?
您设置为标记丢失的数据点。
这是一个完成您最初要求的示例:过滤 -nan
, inf
等等。为了测试,我使用了以下数据文件:
1 0
2 nan
3 -inf
4 2
5 -NaN
6 1
绘图脚本可能如下所示:
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
这给出了以下输出:
所以 plot 命令会跳过所有缺失的数据点。您可以细化
sed
过滤以用 ?
替换任何非数字值,如果这个变体还不够。这工作正常,但只允许选择列,例如与
using 1:2
,但不对列进行计算,例如using ($1*0.1):2
.为此,您可以过滤掉包含 nan
的任何行。 , -inf
等 grep
,就像它在 gnuplot missing data with expression evaluation 中所做的那样(感谢@Thiru 提供链接):filter = 'grep -vi -- "-\?\(nan\|inf\)"'
set offset 0.5,0.5,0.5,0.5
plot '< '.filter.' data.txt' with linespoints ps 2 notitle
关于gnuplot - 在 gnuplot 中,使用 "set datafile missing",如何同时忽略 "nan"和 "-nan"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18718100/