【问题标题】:Gnuplot , pm3d with contour linesGnuplot , pm3d 与等高线
【发布时间】:2016-03-05 19:35:59
【问题描述】:

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

我尝试了命令:“set contour base”,但只出现了 1 行,我认为应该是很多行。见matlab图片

当我在 gnuplot 中绘制它时,我只在左上角得到 1 条轮廓线。但其他一切都是正确的。

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

我还找到了这个例子:见 cmets 中的链接(没有足够的代表),但我不明白应该将 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

【问题讨论】:

标签: plot gnuplot streamline


【解决方案1】:

您缺少的是告诉 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

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

【讨论】:

  • 感谢您的大力帮助。当你尝试你的脚本时,你得到了正确的情节吗?我得到一个非常奇怪的情节和画面。我所做的只是尝试复制粘贴您的脚本。 imgur.com/XglajhS
  • 对不起,我不得不搞砸 gnuplot shell...我更新了答案。
猜你喜欢
  • 1970-01-01
  • 2019-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多