3

I have a text file with data of the style:

0 0 123
0 1 1345
. . .
x(int) y(int) intensity(double)
. . .
0 max size y 1345
1 0 564
. . .
max size x max size y intensity last point

this data represents a 2D map of a substance diffusing on it which I can draw with colours just by using 1:2:3 w image command like:

plot data.dat u ($1):($2):3 w image

My problem now is: I also know the boundary conditions of my 2D plane, this is, not every square of the 2D plane is available to the substance diffuse and, although I know in these areas the intensity will be 0, I would like to draw these areas with a pattern fill. For knowing these regions I have another file with:

0 0 1
0 1 0
. . .
x(int) y(int) value
. . .
0 max size y 0
1 0 0
. . .
max size x max size y value last point

where value is 0 if it is an accessible region or 1 if it is not. How would you draw this part?

Learning from masters
  • 2,032
  • 3
  • 29
  • 42

1 Answers1

3

It's not a very "efficient" solution, nevertheless in order to fill the mask with a pattern, one could process the corresponding file and place a rectangle at every coordinate marked as "accessible".

The script below first determines the number of records in the mask file via the stats command, processes this file in a loop and in each iteration extracts the corresponding row. If the value in the third column (saved into the variable z) is equal to 1, it produces an elementary rectangle at the corresponding position.

fName = 'mask.dat'
stats fName nooutput

unset key
set size ratio -1
set xtics out nomirror
set ytics out nomirror

w = 1.
h = 1.
set xr [STATS_min_x-w/2:STATS_max_x+w/2]
set yr [STATS_min_y-h/2:STATS_max_y+h/2]

#unset colorbox

do for [i=0:STATS_records-1] {
    stats fName using (x=$1, y=$2, z=$3) every ::i::i nooutput
    if(z == 1){
        set object \
            rectangle \
            center x,y \
            size w,h \
            fc rgb 'red' \
            fs transparent pattern 4 \
            noborder \
            front
    }
}

set palette defined (0 "black", 1 "white")
plot 'data.dat' u 1:2:3 w image

With random data (generated on a 20x20 grid), this produces: enter image description here

ewcz
  • 12,819
  • 1
  • 25
  • 47