使用gnuplot绘制最大点

时间:2014-05-09 20:09:42

标签: graph charts plot gnuplot heatmap

我有一个表面热图,想要在最大值上绘制一个点。数据文件有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处绘制点?

2 个答案:

答案 0 :(得分:2)

这是一种可能性:

  • 首先使用set dgrid3dset 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):

enter image description here

答案 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