How do I skip rows in Gnuplot when plotting a heat map?

旧巷老猫 提交于 2019-12-06 10:59:38

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

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

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!