2
votes

I'm trying to plot a heat map in Gnuplot:

set view map
set size square
set cbrange [0:1]
splot "input.dat" 1:4:8 w pm3d

But I want to skip the rows with the data in the first & fourth column in a particular range without changing xrange and yrange. How can I do that?

2

2 Answers

5
votes

If you want to skip x values between xmin and xmax, and y values between ymin and ymax you can do a conditional plot:

splot "input.dat" u 1:4:( $1 >= xmin && $1 <= xmax && \
                          $4 >= ymin && $4 <= ymax ? 1/0 : $8 ) w pm3d

The code above tells gnuplot to ignore the points outside of range.

For instance, I generate the following random data with bash:

for i in `seq 1 1 100`
do for j in `seq 1 1 100`
do echo $i $j $RANDOM >> input.dat
done
echo "" >> input.dat
done

And now tell gnuplot to ignore a certain region:

xmin = 25; xmax = 36; ymin = 67; ymax = 88
set view map
splot "input.dat" u 1:2:( $1 >= xmin && $1 <= xmax && \
                          $2 >= ymin && $2 <= ymax ? 1/0 : $3 ) w pm3d not

enter image description here

If you have multiple regions that you want to skip simply use an "or" logical operator || to delimit areas:

xmin1 = 25; xmax1 = 36; ymin1 = 67; ymax1 = 88
xmin2 = 50; xmax2 = 90; ymin2 = 23; ymax2 = 34
set view map
splot "input.dat" u 1:2:( \
      ($1 >= xmin1 && $1 <= xmax1 && $2 >= ymin1 && $2 <= ymax1) \
      || \
      ($1 >= xmin2 && $1 <= xmax2 && $2 >= ymin2 && $2 <= ymax2) \
      ? 1/0 : $3 ) w pm3d not

enter image description here

1
votes

well.....i found it myself. Thanx !!!

set view map
set size square
set cbrange [0:1]
set xrange [-2.5:2.5]
set yrange [-2.5:2.5]
splot "input.dat" u ($1>=-1 && $1<=1?$1:1/0):($4>=-1 && $4<=1?$4:1/0):8 with pm3d

This will skip the rows if the values in column $1 and $4 are less than -1 or greater than 1