1

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?

0

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

3 Comments

I get 2 errors with your commands. The first is on your 2nd statement: "Tabular output of this 3D plot style not implemented". The second is on the 5th statement: ""d.plot", line 7: No valid data points found in file", which is probably caused by the first error.
Don't worry, my problem was that my data in d.dat was seperated by tabs instead of spaces. Thanks it works now.
Might be a different question, but in addition to the point, I want to plot the x, y an z values of the maximum point, right next to the red dot. How does one do that?
1

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

1 Comment

Also a nice solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.