gnuplot条件绘图:绘图col A:col B如果col C == x

jit*_*hsk 28 gnuplot

我怎么能在gnuplot中这样做:

plot "test.csv" using 1:2 if value_in_column_3 == 80.0
Run Code Online (Sandbox Code Playgroud)

它应该只选择第3列== 80.0的行并忽略所有其他行(它不应该为其他行绘制0,只需忽略它们)

提前致谢.

chl*_*chl 37

考虑以下数据集(1.dat),

1 0.8 0
2 0.6 0
3 0.9 1
4 1.1 0
5 0.7 0
6 0.6 1
Run Code Online (Sandbox Code Playgroud)

我们只想在第三列等于零的情况下绘制前两列.然后你可以尝试这个:

plot '1.dat' using 1:($3==0?$2:1/0)
Run Code Online (Sandbox Code Playgroud)

(感谢 Gnuplot邮件列表上的markjoe.)

  • 请注意,由于`1/0`是无效值,如果选择绘制`lines`或`linespoints`,这将导致问题; 这在http://stackoverflow.com/questions/11187691/gnuplot-conditional-plotting-2-15-2-1-0-with-lines中讨论 (6认同)
  • 使用“NaN”代替“1/0”会更好。 (3认同)

tfl*_*tre 17

需要在包含文本的另一列上有条件地绘图的情况:

数据

1 0.8 a
2 0.6 a
3 0.9 a
1 2.1 b
2 1.7 b
3 1.6 b
Run Code Online (Sandbox Code Playgroud)

set terminal postscript color
set xrange [0:4]
set yrange [0:3]
plot "1.dat" using 1:(stringcolumn(3) eq "a"? $2:1/0) title "a" lc rgb "blue" ,\
  "" using 1:(stringcolumn(3) eq "b"? $2:1/0) title "b" lc rgb "red"
Run Code Online (Sandbox Code Playgroud)

命令

gnuplot < 1.par > 1.ps
Run Code Online (Sandbox Code Playgroud)


小智 5

正如chl上面所说,在gnuplot中执行此操作的唯一方法是相当hacky:您必须使用gnuplot的terniary?:运算符来生成要从数据集中过滤掉的点的数字错误.

我可能在这里有偏见,因为我是该项目的作者,但您可能想看看Pyxplot http://www.pyxplot.org.uk(也是免费和开源),由一组gnuplot编写有点厌倦了像这样的hacky语法的用户.

它的语法与gnuplot非常相似,但有扩展名.根据需要,您可以在plot命令中指定"选择标准",只有在测试为True时才包含点.有关详细信息,请参阅http://pyxplot.org.uk/current/doc/html/sec-select_modifier.html.


小智 5

另一个hack是使用shell命令,如awk:

plot "< awk '$3==80.0 { print $1, $2 }' test.csv" using 1:2
Run Code Online (Sandbox Code Playgroud)


小智 5

如果您正在调用脚本,请使用column(2)而不是$2

plot "1.dat" using 1:(stringcolumn(3) eq "a"? column(2):1/0) title "a" lc rgb "blue" ,\
  "" using 1:(stringcolumn(3) eq "b"? column(2):1/0) title "b" lc rgb "red"
Run Code Online (Sandbox Code Playgroud)