2
votes

I have a text file which contains three columns: latitude, longitude and a percentage. The text file looks like this (link here):

25.00  -28.00    0.3
25.00  -27.00    0.7
25.00  -26.00    1.6
25.00  -25.00    4.3
25.00  -24.00   10.0
25.00  -23.00   18.2
25.00  -22.00   33.9
25.00  -21.00   49.1
...

I want to plot this pertentages as a heatmap on top of a world map (the file for the world map for GNUPlot can be downloaded from the website author here)

The problem is with the colorbar, which I want to group the values by irregular regions (percentiles). As it is difficult to explain, I am attaching an image if what I get with GNUPlot and another plot with the desired result:

GNUPlot try: enter image description here

The code to generate the plot is:

set palette maxcolors 10
set palette defined (0 "#000090",1 "#000fff", 2 "#0090ff",3 "#0fffee",4 "#90ff70",5 "#ffee00",6 "#ff7000",7 "#ee0000",8 "#7f0000", 9 "#7f0050")
set cbtics (99.9 , 99.6, 99.0, 97.5, 95.0, 90.0, 75.0, 50.0, 20.0, 10.0);
plot [-30:40][25:70] "HeatMap_Test.txt" u 2:1:3 pt 5 ps 2 lc palette notitle, "world_10m.txt" with lines ls 1 notitle

Desired Result: enter image description here

Besides from the colors in GNUPlot (which they are not the final ones), you can see that the colorbar tics distribute linearly (making the ones over 99.0 stick all toguether) and are not grouped by the regions defined by the colorbar tics.

Is there a way to do this plot in GNUPlot?

EDIT: The second part of the question continues here

1

1 Answers

3
votes

You can define a step function which maps the z column as needed.

reset

step(x) = (x < 15.0  ? 0 : \
          (x < 35.0  ? 1 : \
          (x < 62.5  ? 2 : \
          (x < 82.5  ? 3 : \
          (x < 92.5  ? 4 : \
          (x < 96.25 ? 5 : \
          (x < 98.25 ? 6 : \
          (x < 99.3  ? 7 : \
          (x < 99.75 ? 8 : 9 )))))))))

set palette maxcolors 10
set palette defined (0 "#333399", 1 "#3333f7", 2 "#3373ff", 3 "#33c6ff", \
                     4 "#5affd2", 5 "#9cff8f", 6 "#dfff4c", 7 "#ffc733", \
                     8 "#ff7a33", 9 "#e53333")

set cbrange [-0.5:9.5]
set cbtics nomirror
set cbtics ( "99.9" 9, "99.6" 8, "99.0" 7, "97.5" 6, "95.0" 5, \
             "90.0" 4, "75.0" 3, "50.0" 2, "20.0" 1, "10.0" 0 )

set terminal pngcairo
set output "output.png"
set xrange [-30:40]
set yrange [ 25:70]
plot "HeatMap_Test.txt" u 2:1:(step($3)) notitle pt 5 ps 2 lc palette, \
     "world_10m.txt" notitle with lines ls 1 lc -1
set output

I have nested the ternary operator several times to map the irregular percentage ranges 0 ... 100 into a linear cbrange -0.5 ... 9.5.

This is the result with Gnuplot 4.6:

irregular percentile tics