Gnuplot - graphing a matrix and replacing the squares with figures

Viewed 65

I'm using gnuplot to graph a 80x80 matrix from a dataset with the following code:

set terminal png
set output "Matrix.png"
set title "Matrix"
set autoscale xfix
set autoscale yfix
set palette define (0 "black", 1 "red", 2 "blue", 3 "yellow", 4 "gold", 5 "green")
set cbrange [0:5]
plot "Lattice.txt" matrix with image

Now I need to do two modifications, the first one is to have it on a grayscale which I figure I can do by replacing the palette with set palette gray

The second want is to replace each square with figures, or show the figures inside the squares. figures likes triangles, crosses, circles.

Is there a way to define each number with each symbol, like I did previously with the palette colours?

Thanks.

1 Answers

If I understood your question correctly, you can do the same with variable pointtypes. Check help points. Type test in the gnuplot console and you will see the available pointtypes. The example below is still with color palette because it looks nicer.

Code:

### variable pointtype
reset session
set size square

# create some random test data
set print $Data
    do for [y=1:15] {
        Line = ''
        do for [x=1:15] {
            Line = Line.sprintf(" %d", int(rand(0)*6))
        }
        print Line
    }
set print

set palette define (0 "black", 1 "red", 2 "blue", 3 "yellow", 4 "gold", 5 "green")

myPointtypes     = "2 5 7 9 11 13"
myPointtype(col) = int(word(myPointtypes,int(column(col))+1))

set offsets 0.5,0.5,0.5,0.5

plot $Data u 1:2:(myPointtype(3)):3 matrix w p pt var lc palette notitle
### end of code

Result:

enter image description here

Related