带轮廓线的gnuplot,pm3d [英] Gnuplot , pm3d with contour lines

查看:99
本文介绍了带轮廓线的gnuplot,pm3d的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是3d绘制带有一些值的矩阵,并且我需要在图中添加轮廓线,是否有一个简单的gnuplot命令来执行此操作?

我尝试了命令:设置轮廓基准",但只出现了1行,我认为应该多行.看到matlab图片

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

我的目标是使它在Matlab中像这样 Matlabplot

我也找到了此示例:请参见注释中的链接(没有足够的代表),但是我不明白我应该在哪里放置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

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

i am 3d plotting a matrix with some values, and i need to add contour lines to the plot, is there a simple gnuplot command to do this?

I tried the command: "set contour base" but only 1 line came up, i think it should be many lines. See matlab picture

When i plot it in gnuplot i only get 1 contour line in the top left corner.But everything else is correct.

My goal is to get it to look like in matlab like this Matlabplot

I also found this example: see link in comments (dont have enough rep), but i dont understand where i should put in the data values from test.txt

test.txt

test.txt

gnuplot commands

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

解决方案

What you are missing is to tell gnuplot where to put the contours. This is done via the set cntrparam levels incr -0.3,0.1,0.5 command which means: start at -0.3 and trace a contour every o.1 up to 0.5.

AFAIK if you want to make contours all black, you have to save the contour lines in a temporary file (here contour.txt).

So your script would be

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"

which gives you this:

Note:

you can get rid of interpolation file (dgrid.txt) if you format a bit your datafile by leaving a blank line after each row (i.e. every 30 datapoints) because they are already mesh-ordered.

This could be done also with a awk script. But I'm too lazy to look into it...

The rest will remain the same and will work as expected.

here is how it should look like :

In which case the script would simply become:

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

with no need of ntermediate file and with better contour since data in not interpolate by gridded:

这篇关于带轮廓线的gnuplot,pm3d的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆