Alex Rivera | Logout

gnuplot conditional plotting: plot col A:col B if col C == x

Asked 2011-07-03T18:01:11.777
38

How can I do this in gnuplot:

plot "test.csv" using 1:2 if value_in_column_3 == 80.0

It should only select those rows where column 3 == 80.0 and ignore all other rows (It should not plot a 0 for the other rows, simply ignore them)

Thanks in advance.

Edit
Report

1 Answer

22

Case where one wants to plot conditionally on another column containing text:

data

1 0.8 a
2 0.6 a
3 0.9 a
1 2.1 b
2 1.7 b
3 1.6 b

code

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"

command

gnuplot < 1.par > 1.ps
answered 2012-02-07T19:16:42.320

Your Answer