Question

I have a surface heat map and want to draw a point on the maximum value. The data file has 3 columns, x, y and z. I want to plot a point at the x and y coordinates where the value of z is a maximum. This is what I currently have:

set style data lines
set dgrid3d 20,200
set pm3d map
splot "d.dat" u 1:2:3

How can I plot a point at GPVAL_DATA_Z_MAX?

Was it helpful?

Solution

Here is one possibility:

  • First draw the gridded data which you get with set dgrid3d to a temporary file using set table.
  • Use stats to get the maximum value (the splot inside the set table doesn't set the GPVAL_DATA_Z_MAX variable).
  • Plot the tabulated data with image to get your heatmap. Using this plotting style instead of pm3d makes sure, that the maximum value is located centered in a 'pixel'.
  • Plot a point only when the third column in the tabulated data corresponds to the maximum value.

The complete script:

set dgrid3d 20,200

set table 'd.table'
splot 'd.dat' u 1:2:3
unset table

stats 'd.table' u 3 nooutput

unset dgrid3d
set autoscale fix
unset key
plot 'd.table' with image,\
     '' using 1:($3 == STATS_max ? $2 : NaN) with points pt 7

Using an example file

0 0 5
0 1 7
0 2 9

1 0 2
1 1 0
1 2 10

2 0 1
2 1 1
2 2 8

and set dgrid3d 4,4 gives you the following output (using 4.6.4):

enter image description here

OTHER TIPS

I've found a better solution (in my opinion) that directly reads the values from file a plots the point. Only works on Linux:

input = "d.dat"

# Calculate max values
maxz = real(system(sprintf("awk 'BEGIN {max = 0} {if (NR > 2 && $3 > max) max = $3} END {print max}' %s", input)))
maxx = real(system(sprintf("awk '$3 ~ %g { print $1 }' %s", maxz, input)))
maxy = real(system(sprintf("awk '$3 ~ %g { print $2 }' %s", maxz, input)))

# Plot point
set label 1 " " center front at maxx,maxy point pt 7 ps 1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top