使用 GNUplot 设置等高线标签、网格和颜色图插值?

Setting contour labels, grid, and colormap interpolation with GNUplot?

所以我一直在尝试创建一个热图,其中等高线图覆盖在二维数组的顶部。我基本上是成功的,但我被困住了。

问题 1: 我无法在每个轮廓上显示标签。我在情节之前设置了这些命令:

                    set cntrlabel start 1 interval 1

此命令应将标签放置在间隔为 1 的第一条轮廓线上(在每个轮廓上放置标签)。然而什么也没有出现。

问题 2:(已解决) 我无法正确显示网格。如果我删除绘制颜色图的 plot 命令部分,网格将出现在仅轮廓版本上。绘制两个图时,不会出现网格。为什么会这样?

问题 3: 我正在尝试使用 pm3d 来插值颜色图。正如您从我的输出中看到的那样,颜色图非常 'rough'。我已经在类似的示例中成功地尝试了这些命令。

set pm3d map

set pm3d interpolate 4,4

然而,当我在此示例中使用它时,GNUplot 使用空文件创建数据文件 test.dat,并且未创建颜色图。 GNUplot 创建此错误消息:

第 0 行:警告:跳过没有有效点的数据文件

我使用的命令[pm3d命令会导致绘图错误]:

                    cd '<Your Directory>'

                    set terminal png size 1920,1080 
                    set output 'testplot.png'
                    set xrange [0:20]
                    set yrange [0:25]
                    set pm3d map 
                    set pm3d interpolate 4,4
                    set table 'test.dat'
                    splot 'TestData.txt' matrix
                    unset table

                    set contour base
                    set cntrparam level incremental 0, 0.1, 1
                    unset surface
                    set table 'cont.dat'
                    splot 'TestData.txt' matrix
                    unset table

                    reset
                    set xrange [0:20]
                    set yrange [0:25]
                    unset key
                    
                    set cbtics 0, 0.1, 1.0
                    set cblabel 'Normalized Power Density Relative to SC6 Limit'
                    set cbrange [0:1]
                    set cntrparam level incremental 0, 0.1, 1
                    set cntrlabel start 1 interval 1
                    set grid
                    p 'test.dat' with image, 'cont.dat' w l lt - 1 lw 1.5 

Link to TestData.txt which is arbitrary 2d array

My current plot output

example desired output plot (with smooth heatmap, contour labels, but no grid)

如有任何帮助,我们将不胜感激。

1) 版本 5 中更改了标记轮廓的机制。它现在需要一个单独的绘图命令 with labels,在 set contour 生效时发出。

2) 使用set grid front确保它绘制在绘图元素的顶部

3) set pm3d map 已弃用。我不再确定它过去是做什么的。总之没必要。 set pm3d interpolate x,x 对我有用。

修改后的脚本和输出如下

# Require "with pm3d"
set pm3d explicit

# Smooth pm3d colors
set pm3d interpolate 3,3

set contour
set cntrparam level incremental 0, 0.1, 1

set view map
unset key
unset border

set xrange [*:*] noextend
set yrange [*:*] noextend

# Plot elements will be rendered in the order given.
# The grid will go in front of that.
set grid x y lc "white" front

# Note that grid lines only appear at axis tic locations.
# But black tics would hide the white grid lines, so scale them to 0 length
set tics scale 0

splot 'TestData.txt' matrix using 1:2:3 with pm3d, \
      '' matrix using 1:2:3 with lines lw 4 nosurface, \
      '' matrix using 1:2:3 with labels textcolor "white"