我怎样才能在gnuplot中执行此操作:
plot "test.csv" using 1:2 if value_in_column_3 == 80.0
它应该只选择第3列== 80.0的行并忽略所有其他行(不应该为其他行绘制0,只需忽略它们)
提前致谢。
答案 0 :(得分:36)
考虑以下数据集(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
我们只想在第三列等于零时绘制前两列。然后你可以试试这个:
plot '1.dat' using 1:($3==0?$2:1/0)
(感谢Gnuplot邮件列表上的markjoe。)
答案 1 :(得分: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
码
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"
命令
gnuplot < 1.par > 1.ps
答案 2 :(得分:5)
正如上面所说,在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。
答案 3 :(得分:5)
另一个黑客是使用像awk
这样的shell命令:
plot "< awk '$3==80.0 { print $1, $2 }' test.csv" using 1:2
答案 4 :(得分:3)
如果您要调用脚本,请使用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"