我想使用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
但我明白了:
这不是我预期的结果。我能做什么?我想让数据线交错。
答案 0 :(得分:4)
基本上,gnuplot
区分丢失和无效的数据点,例如, In gnuplot, with “set datafile missing”, how to ignore both “nan” and “-nan”?。
如果您有未定义的点(例如NaN
或1/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
这给出了:
在左图中,绘制了点,但没有用线连接,因为它们之间存在“无效”点。