Saturday, 15 January 2011

gnuplot - change from 2d points to heatmap -



gnuplot - change from 2d points to heatmap -

i trying convert plot using points heatmap. info in x,y,z format x,y beingness lat / lon , z beingness # of recorded instances

we plot using:

plot 'data.dat' u 1:2:3 points pointtype 13 lc palette, \ 'boundary.dat' lines ls 1

i able plot heatmap 3 plots: 1. base of operations heatmap of values 2. points @ maybe 50% opacity show underlying geo path 3. line representing boundary.

sample image: image on left gnuplot, 1 on right qgis. gnuplot produce similar 1 on right.

peter

nice question :)

you'll need few steps proper result:

in order heatmap, must create regular grid , interpolate data. can done set dgrid3d. because want interpolation of info must write interpolation 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, can utilize set datafile separator ',' utilize commas delimiters, temporary file data-heatmap.dat' contains columns separated spaces, must usetr` replace commas white spaces.

then can plot together. finish script might follows:

# diverging color palette 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 prepare 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 smoother interpolation, utilize set dgrid3d 200,200,1 or similar. maybe want set fixed color range set cbrange.

the result 4.6.5 is:

the dimensions of generated grid derived bounding box of scattered data. hack extend part of interpolation can add together 2 dummy points on-the-fly when creating interpolated data: 1 point @ upper right , 1 @ upper left. later can right bit these points set offsets:

# diverging color palette 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 prepare 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

gnuplot heatmap

No comments:

Post a Comment