Gnuplot ,带有等高线的 pm3d

Gnuplot , pm3d with contour lines

我正在 3d 绘制一个具有一些值的矩阵,我需要在绘图中添加等高线,是否有简单的 gnuplot 命令可以执行此操作?

我试过命令:"set contour base"但只出现了 1 行,我认为应该有很多行。见matlab图片

当我在 gnuplot 中绘制它时,我只在左上角得到 1 条等高线 corner.But 其他一切都是正确的。

我的目标是让它在 matlab 中看起来像这样 Matlabplot

我还发现了这个例子:请参阅评论中的 link(没有足够的代表),但我不明白我应该把来自 test.txt

的数据值放在哪里

test.txt

test.txt

gnuplot 命令

set view map
set yrange [0:30]
set xrange [0:30]
set dgrid3d 100,100,4
set contour base
splot 'test.txt' u 1:2:3 w pm3d

您缺少的是告诉 gnuplot 在哪里放置等高线。这是通过 set cntrparam levels incr -0.3,0.1,0.5 命令完成的,这意味着: 从 -0.3 开始,每隔 o.1 跟踪一个轮廓,直到 0.5

AFAIK 如果你想让轮廓全黑,你必须将轮廓线保存在一个临时文件中(这里 contour.txt)。

所以你的脚本应该是

reset
set contour
unset surface
set cntrparam levels incr -0.3,0.1,0.5

set view map
set xrange [0:30]
set yrange [0:30]

set dgrid3d 100,100,4

set table "contour.txt"
splot 'test.txt'
unset table

unset contour
set surface
set table "dgrid.txt"
splot 'test.txt'
unset table

reset
set pm3d map
unset key
set palette defined (0 '#352a87', 1 '#0363e1',2 '#1485d4', 3 '#06a7c6', 4 '#38b99e', 5 '#92bf73', 6 '#d9ba56', 7 '#fcce2e', 8 '#f9fb0e')
set autoscale fix
set grid

splot 'dgrid.txt' w pm3d, 'contour.txt' w l lc rgb "black"

这给了你这个:

注:

如果您通过在每行(即每 30 个数据点)后留下一个空行来格式化您的数据文件,您可以摆脱插值文件(dgrid.txt),因为它们已经是网格排序的。

这也可以通过 awk 脚本来完成。但是我懒得研究了...

其余部分将保持不变,并按预期工作。

它应该是这样的:

在这种情况下,脚本将简单地变为:

set pm3d map impl
set contour
set style increment user
do for [i=1:18] { set style line i lc rgb "black"}
set cntrparam levels incr -0.3,0.1,0.5
set palette defined (0 '#352a87', 1 '#0363e1',2 '#1485d4', 3 '#06a7c6', 4 '#38b99e', 5 '#92bf73', 6 '#d9ba56', 7 '#fcce2e', 8 '#f9fb0e')
set autoscale fix
splot 'test.txt' w pm3d notitle

不需要中间文件并且具有更好的轮廓,因为数据不通过网格插值: