0
votes

I would like to plot a heatmap using gnuplot.

My data is (file.txt):

5   0   0.0531072048
5   5   0.3476492247
5   10  0.322184913
5   20  0.2824368116
5   50  0.2919607884
10  0   0.0472727812
10  5   0.3578374264
10  10  0.3483726737
10  20  0.3212322874
10  50  0.3017652051
20  0   0.0536101408
20  5   0.3460970331
20  10  0.3589370763
20  20  0.412912733
20  50  0.3907459465
50  0   0.0497156879
50  5   0.3611165857
50  10  0.4046003446
50  20  0.4620183753
50  50  0.4156261444
100 0   0.0483082089
100 5   0.3815755779
100 10  0.4031628253
100 20  0.4537462156
100 50  0.4231632329

When I type the below command

plot "file.txt"  using 1:2:3 w image

It generates a heatmap. However, the grid does not exactly correspond to the data. There is a 5-by-5 grid but the axis labels of the grid cells do not correspond to the values in the first two columns of file. Also all the grid cells have equal sizes. However, they should be varying sizes.

Let me try to explain what I expect to have. The plot below was generated with the following commands:

set xrange [-10:110]
set yrange [-10:60]
plot "file.txt"

data points

Each "+" in this plot corresponds to a row of the first two columns (x and y) of the file. For each "+", in the third column there is a value (z). This z value is the result of the experiment for the parameter values x and y. I expect to see the z values as colored grid cells just around the "+" signs. That is, the gird cells' center should be these "+" signs. Naturally, the grid cells will be rectangles of different sizes. I hope I made it a little bit more clear.

Any help will be appreciated. Ahmet

1
Does it help if you replace plot with splot? Use set view map before the plotting command. - giordano
@giordano, this changed the grid sizes somewhat but this is still not what I want, thanks. - Ahmet Yılmaz
Can you please post an example of the expected result? - giordano
Hi @giordano I have tried to explain what I expect to see at the end of the original post. - Ahmet Yılmaz

1 Answers

1
votes

How about

set pm3d map # depening on what you want
splot "file.txt" w pm3d

for this to work you need to change your data file and add some newlines like this

5   0   0.0531072048
5   5   0.3476492247
5   10  0.322184913
5   20  0.2824368116
5   50  0.2919607884

10  0   0.0472727812
10  5   0.3578374264
10  10  0.3483726737
10  20  0.3212322874
10  50  0.3017652051

20  0   0.0536101408
20  5   0.3460970331
20  10  0.3589370763
20  20  0.412912733
20  50  0.3907459465

50  0   0.0497156879
50  5   0.3611165857
50  10  0.4046003446
50  20  0.4620183753
50  50  0.4156261444

100 0   0.0483082089
100 5   0.3815755779
100 10  0.4031628253
100 20  0.4537462156
100 50  0.4231632329

Or you could just change the plot you made to inlcude color according to the z values. Something like this?

set xrange [-10:110]
set yrange [-10:60]
plot "file.txt" u 1:2:3 w p pt 7 ps 4 palette

Here you could play with the pt too.