我有一个表面热图,想要在最大值上绘制一个点。数据文件有3列,x,y和z。我想在x和y坐标处绘制一个点,其中z的值是最大值。这就是我目前所拥有的:
set style data lines
set dgrid3d 20,200
set pm3d map
splot "d.dat" u 1:2:3
如何在GPVAL_DATA_Z_MAX处绘制点?
答案 0 :(得分:2)
这是一种可能性:
set dgrid3d
将set table
获得的网格化数据绘制到临时文件中。stats
获取最大值(splot
中的set table
不会设置GPVAL_DATA_Z_MAX
变量。with image
以获取热图。使用此绘图样式而不是pm3d
可确保最大值位于'像素的中心位置。完整的脚本:
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
使用示例文件
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
和set dgrid3d 4,4
为您提供以下输出(使用4.6.4):
答案 1 :(得分:1)
我找到了一个更好的解决方案(在我看来)直接读取文件中的值a绘制点。仅适用于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