3
votes

I would like to plot a simple heatmap with Gnuplot which is very similar to this example:

unset key
set cbrange [0:6]
set xrange [0:10]
set yrange [0:5]
set size ratio -1
set cbtics out nomirror
set palette maxcolors 12 model RGB defined (0 '#1a9641', 1 '#a6d96a', 2 '#ffffbf', 3 '#fdae61', 4 '#d7191c')
$map1 << EOD
5.5 4.0 3.5 1.0 0.5 5.0 4.5 3.0 1.5 0.0
2.0 2.5 0.0 inf inf 4.5 3.0 0.5 0.0 1.5
0.5 0.0 0.5 inf inf 0.0 0.5 0.0 1.5 0.0
0.0 0.5 0.0 2.5 3.0 0.5 0.0 0.5 2.0 3.5
0.5 1.0 2.5 4.0 3.5 2.0 2.5 0.0 0.5 1.0
EOD
plot '$map1' using ($1+.5):($2+.5):($3) matrix with image

This is the corresponding plot: enter image description here

As you can see the matrix contains infinity values. I would like to add an extra color (for example blue) to the colorbox especially for infinity values (the big red square in the middle should appear blue).

At first I thought that I just have to add one more color in the end of my defined color values for the colorbox. But this will result in an color transition between the last two colors (red and blue) because blue would be the associated color for the max value of cbrange. But the max value of non infinity values should stay 6 and red.

The result should look something like this: enter image description here

Any ideas out there?

1

1 Answers

3
votes

You'll need something like the following three lines, filling in colors 0-11 manually according to your desired gradient (I've used this site to generate gradients in the past.)

set cbrange [0:6.5]
set palette maxcolors 13 model RGB defined \
( 0 '#222222', 1 '#333333',   2 '#444444', \
  3 '#555555', 4 '#666666',   5 '#777777', \
  6 '#888888', 7 '#999999',   8 '#aaaaaa', \
  9 '#bbbbbb', 10 '#cccccc', 11 '#dddddd', 12 '#dd0000')
set cbtics ("0" 0, "1" 1, "2" 2, "3" 3, "4" 4, "5" 5, "6" 6, "inf" 6.5)