完全忽略Gnuplot中的一些数据行

时间:2013-09-25 09:02:08

标签: gnuplot pivot-table

我想使用Gnuplot绘制一种PivotChart。 所以我需要忽略我文件中的一些数据行。 我尝试了以下方法:

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

但我明白了: Bad charts

这不是我预期的结果。我能做什么?我想让数据线交错。

1 个答案:

答案 0 :(得分:4)

基本上,gnuplot区分丢失和无效的数据点,例如, In gnuplot, with “set datafile missing”, how to ignore both “nan” and “-nan”?

如果您有未定义的点(例如NaN1/0),则绘图线会被中断。要实现此目的,您需要设置datafile missing。但是,如果您在using语句中评估某些内容,那么这不起作用,因为对于'undefined'而言它太晚了< - > '缺少'选择(选择列,例如using 1:4即可)。声明

set datafile missing '?'
plot 'forStackoverGnuplot.txt' using 1:(($2==0 && $3==4) ? $4 : '?')

工作。

相反,您必须在外部过滤数据,并在绘制之前删除受影响的行:

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

这给出了:

enter image description here

在左图中,绘制了点,但没有用线连接,因为它们之间存在“无效”点。

相关问题