【问题标题】:Completely ignore some lines of data in Gnuplot完全忽略 Gnuplot 中的一些数据行
【发布时间】:2014-04-13 20:07:26
【问题描述】:

我想使用 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

但我得到:

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

【问题讨论】:

    标签: gnuplot pivot-table


    【解决方案1】:

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

    如果你有一个未定义的点(例如NaN1/0),情节线被中断。为此,您需要设置datafile missing。但是,如果您在 using 语句中评估某些内容,这将不起作用,因为对于“未定义”“缺失”选项来说为时已晚(选择列,例如使用 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
    

    这给出了:

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

    【讨论】:

      猜你喜欢
      • 2016-06-02
      • 1970-01-01
      • 2012-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-16
      • 1970-01-01
      相关资源
      最近更新 更多