我想使用 Gnuplot 绘制一种数据透视图。
所以我需要忽略文件中的一些数据行。
我尝试了以下方法:
unset key
set xtics font "Times-Roman, 5"
set ytics font "Times-Roman, 5"
set multiplot layout 4,3 #title "Multiplots\n"
plot [7:50][0:1] 'forStackoverGnuplot.txt' using 1:($2==0?($3==4?$4:NaN):NaN) with lines ti '4'
plot [7:50][0:1] 'forStackoverGnuplot.txt' using 1:($2==0?($3==4?$4:"fe"):"fe") with lines ti '4'
数据文件:
20 0 5 0.668593155
7 0 4 0.885223087
20 0 5 0.668593155
10 0 4 0.92239289
20 0 5 0.668593155
20 0 4 0.834947746
30 0 4 0.693726036
50 0 4 0.47169919
But I get:
这不是我期望的结果。我能做些什么?我想让数据线交错。
基本上,gnuplot
区分丢失和无效的数据点,参见例如在gnuplot中,“设置数据文件丢失”,如何忽略“nan”和“-nan”? https://stackoverflow.com/a/18718574/2604213.
如果你有一个未定义的点(例如NaN
or 1/0
),剧情被打断。为了实现这一点,您需要设置datafile missing
。但如果你评估其中的某些内容,那就行不通了using
语句,因为对于“未定义”“缺失”选择来说已经太晚了(选择列,例如使用using 1:4
没问题)。所以声明
set datafile missing '?'
plot 'forStackoverGnuplot.txt' using 1:(($2==0 && $3==4) ? $4 : '?')
does not work.
相反,您必须在绘制数据之前从外部过滤数据并删除受影响的行:
unset key
set style data linespoints
set multiplot layout 1,2
plot [7:50][0:1] 'forStackoverGnuplot.txt' using 1:(($2==0 && $3==4) ? $4 : 1/0)
filter = '< awk ''{ if ($2 == 0 && $3 == 4) print $1, $2, $3, $4}'' '
plot [7:50][0:1] filter.' forStackoverGnuplot.txt' using 1:4
unset multiplot
这给出:
在左图中,绘制了点,但没有用线连接,因为它们之间存在“无效”点。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)