gnuplot - 在 gnuplot 中,使用 "set datafile missing",如何同时忽略 "nan"和 "-nan"?

标签 gnuplot nan missing-data infinity

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

这给出了以下输出:

enter image description here

所以 plot 命令会跳过所有缺失的数据点。您可以细化 sed过滤以用 ? 替换任何非数字值,如果这个变体还不够。

这工作正常,但只允许选择列,例如与 using 1:2 ,但不对列进行计算,例如using ($1*0.1):2 .为此,您可以过滤掉包含 nan 的任何行。 , -infgrep ,就像它在 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/

相关文章:

python-2.7 - 处理 Pandas 和 Numpy 中的缺失数据

bash 在循环时删除我的文件 "~$ ./program > file.dat"(gnuplot)

c - 通过我的 C 程序打开 GnuPlot

matrix - 带有图像和 xrange 的绘图矩阵出现问题

python - 用于 python 插值的 scipy 的 splrep/splev 返回 nan

r - 计算带有缺失值中断的数据范围 - R

c++ - 来自 std::vector<double> 的未格式化流输入

matlab - 图像处理问题 : Fill NaNs in image,,主要由 NaN 组成

javascript - 如何在 JavaScript 中检查一个数字是否为 NaN?

python - 使用 NaN 按列对数据进行 Winsorizing