Nice question :)
You'll need a few steps to get a proper result:
In order to get a heatmap, you must create a regular grid and interpolate your data. This can be done with set dgrid3d
. Because you want the interpolation only for some of your data you must write the interpolation to a temporary file:
set dgrid3d 200,200,2
set table 'data-heatmap.dat'
splot '< tr "," " " < data.dat' using 1:2:3
unset table
unset dgrid3d
Usually, you can use set datafile separator ','
to use commas as delimiters, but the temporary file data-heatmap.dat' contains columns separated by spaces, so you must use
tr` to replace the commas with white spaces.
Then you can plot all together. A complete script might look as follows:
# Diverging color palette from colorbrewer2.org
set palette defined (0 '#006837', 1 '#1a9850', 2 '#66bd63',\
3 '#a6d96a', 4 '#d9ef8b', 5 '#ffffbf',\
6 '#fee08b', 7 '#fdae61', 8 '#f46d43',\
9 '#df3027', 10 '#a50026')
unset key
set dgrid3d 200,200,2
set table 'data-heatmap.dat'
splot '< tr "," " " < data.dat' using 1:2:3
unset table
unset dgrid3d
set autoscale fix
set xtics 0.1
plot 'data-heatmap.dat' u 1:2:3 w image,\
'< tr "," " " < boundary.dat' w l lc rgb 'black' lw 2,\
'< tr "," " " < data.dat' w p pt 7 ps 0.2 lc palette
To get a smoother interpolation, use set dgrid3d 200,200,1
or similar. Maybe you also want to set a fixed color range with set cbrange
.
The result with 4.6.5 is:
The dimensions of the generated grid is derived from the bounding box of the scattered data. As a hack to extend the region of interpolation you can add two dummy points on-the-fly when creating the interpolated data: one point at the upper right and one at the upper left. Later you can correct a bit for these points with set offsets
:
# Diverging color palette from colorbrewer2.org
set palette defined (0 '#006837', 1 '#1a9850', 2 '#66bd63',\
3 '#a6d96a', 4 '#d9ef8b', 5 '#ffffbf',\
6 '#fee08b', 7 '#fdae61', 8 '#f46d43',\
9 '#df3027', 10 '#a50026')
unset key
set dgrid3d 200,200,2
set table 'data-heatmap.dat'
splot '< echo -e "\n-118.62,34.29,1\n-118.10,34.29,1" | paste -s -d "\n" data.dat - | tr "," " "' using 1:2:3
unset table
unset dgrid3d
set autoscale fix
set offsets -0.02,-0.01,-0.01,0.01
set xtics 0.1
plot 'data-heatmap.dat' u 1:2:3 w image,\
'< tr "," " " < boundary.dat' w l lc rgb 'black' lw 2,\
'< tr "," " " < data.dat' w p pt 7 ps 0.2 lc palette