Reputation: 31
I have troubles creating a heat map with gnuplot for data with different scales.
Consider the following sample data set:
0.100 1.000 10.0
0.010 1.000 20.0
0.001 1.000 40.0
0.100 10.00 20.0
0.010 10.00 40.0
0.001 10.00 80.0
0.100 100.0 40.0
0.010 100.0 80.0
0.001 100.0 160.0
If I plot it using a heatmap, it only seems to be correct if I scale the x-values such that they are in the same range as the y-values.
Please find below an illustrating example. Only the second plot gives me the correct values of the heat map (high values in the top left corner, low values in the bottom right corner):
set multiplot layout 2,1
set pm3d
set dgrid3d 20,20
set view map
set xlabel 'unscaled'
splot 'data.dat' u 1:2:3
set xlabel 'scaled by factor 1000'
splot 'data.dat' u ($1*1000):2:3
How can I achieve this also for the non-scaled values?
Any help is appreciated. Many thanks.
Upvotes: 3
Views: 1551
Reputation: 4218
The scaled plot looks correct, but I'm not sure whether it really is correct. At least there seems to be an artifact in the lower left corner, a local maximum which probably should not be there. You can see it better if you remove set view map
:
I think the reason is the dgrid3d
. It does some fancy weighting of the neighboring points which can lead to unexpected results.
My suggestion would be to use a linear interpolation by removing set dgrid3d 20,20
and using set pm3d interpolate 20,20
. This gives the following picture:
Finally, your data somehow asks for at least to try a logscale plot:
My script for the last plot follows. Nothing special compared to yours. I had to specify xrange for the unscaled plot, and it is longer because of the 4 plots.
reset
set terminal png size 1200,800
set output "data_log.png"
set logscale x
set logscale y
set multiplot layout 2,2 title "With \"interpolate\" and logscale"
set pm3d at s interpolate 20,20
set hidden3d
set xlabel 'unscaled'
set origin 0.5,0.5
set xrange [0.001:0.1]
splot 'data.dat' u 1:2:3 notitle
set autoscale x
set xlabel 'scaled by factor 1000'
set origin 0.5,0.0
splot 'data.dat' u ($1*1000):2:3 notitle
set view map
set xlabel 'unscaled'
set origin 0.0,0.5
set xrange [0.001:0.1]
splot 'data.dat' u 1:2:3 notitle
set autoscale x
set xlabel 'scaled by factor 1000'
set origin 0.0,0.0
splot 'data.dat' u ($1*1000):2:3 notitle
unset multiplot
set output
Upvotes: 0
Reputation: 54223
Here you go :
set dgrid3d 20,20
set pm3d explicit
set view map
set table "interpolated_data.dat"
splot 'data.dat' using ($1*1000):2:3
set output 'heatmap.png'
set terminal pngcairo
set multiplot layout 2,1
unset table
unset dgrid3d
set pm3d
unset surface
set xlabel 'scaled by factor 1000'
splot 'interpolated_data.dat' u 1:2:3
set xlabel 'unscaled'
splot 'interpolated_data.dat' u ($1/1000):2:3
Upvotes: 1