在3D图上绘制轮廓,两个不同的数据范围

时间:2020-07-14 11:02:14

标签: gnuplot

我想3D绘制一个数据集,然后将不同的数据集轮廓绘制到单个组合图中。 (对于那些感兴趣的人,轮廓数据集与3Dplot的梯度有关)。改编为from here的代码可以正常工作,除了以下方面:除以下方面:如果我使用set zrange缩放3D图,轮廓将消失。自动调整后的3Dplot看起来不太好,尽管轮廓看起来还可以,这就是为什么我要应用自定义范围的原因。我怀疑问题也与轮廓线的变化有关,而轮廓线也没有留下轮廓线。但是我对Gnuplot的经验不足,无法确定是否确实如此,或者如何解决问题。

此代码...

    reset
    set ztics 5
    #set zrange [10 : 25] #nowriteback
    set view 135,60
    set contour base #surface
    set cntrlabel font ",7"
    set datafile missing "NaN"
    set clabel
    
    set cntrparam levels discrete 0.3, 0.4, 0.6, 1.0, 1.5
    splot 'out011_Io.txt' nonuniform matrix with lines notitle nocontour, \
    'out011_FlxN.txt' nonuniform matrix with lines title "{/Symbol F}_{N}" enhanced nosurface

...创建此图:具有良好轮廓的过度平坦的3D图,

激活zrange时...

reset
set ztics 5
set zrange [10 : 25] #nowriteback
set view 135,60
set contour base #surface
set cntrlabel font ",7"
set datafile missing "NaN"
set clabel

set cntrparam levels discrete 0.3, 0.4, 0.6, 1.0, 1.5
splot 'out011_Io.txt' nonuniform matrix with lines notitle nocontour, \
'out011_FlxN.txt' nonuniform matrix with lines title "{/Symbol F}_{N}" enhanced nosurface

...创建此图:良好的3D图,没有可见的轮廓。

enter image description here

原始数据可在此处找到:out011_FlxN.txtout011_Io.txt

对知识渊博的建议表示高度赞赏。

2 个答案:

答案 0 :(得分:1)

如果您选中help contour,则gnuplot提供绘制轮廓的选项

set contour {base | surface | both}

很遗憾,不是您所要求的自定义级别。 因此,我对以下建议的解决方法是:

  1. 将数据和轮廓绘制到表格中,例如数据块$Cont。此数据块将包含数据和轮廓线(在您的情况下为5)以及每个子块,该子块由2条空行分隔。
  2. 未设置轮廓
  3. 绘制$Cont,但第一个块除外。您的情况是通过index 1:5

说明:

for [i=1:LevelCount] $Cont u 1:2:(10):(column(-2)) index i w l lc var ti columnhead(3) 

使用以$Cont为伪列(10)确定的可变颜色lc var,以恒定的z级(column(-2))绘制columnhead(3)的第1至5个块。显然,在您的情况下,轮廓线只有4条,即0.3处没有轮廓线。

代码:

### contour plot at custom level
reset session

set contour base
set cntrparam levels discrete 0.3, 0.4, 0.6, 1.0, 1.5
set table $Cont
    splot "out011_FlxN2.txt" nonuniform matrix
unset table
unset contour
 
set key at screen 0.16, screen 1 title "{/Symbol F}_{N}"
set view 135,60
set xyplane relative 0
LevelCount = 5

splot "out011_Io.txt" nonuniform matrix w l notitle, \
      for [i=1:LevelCount] $Cont u 1:2:(10):(column(-2)) index i w l lc var ti columnhead(3) 
### end of code

结果:

enter image description here

答案 1 :(得分:0)

在没有包含数据文件的最小示例的情况下,很难确定答案,但这可能是因为第二个文件的值超出了您要为第一个文件强加的zrange。例如,代码:

set cntrparam levels discrete -.5,.5
set contour base
splot 10*(sin(x/3)*sin(y/3)+2), sin(x/3)*sin(y/3) nosurface

会产生轮廓,但是如果您指定不包含zrange且可能不包含-0.5的{​​{1}},也不会显示这些轮廓。由于没有0.5的{​​{1}}关键字(与axes相反),据我所知,您还剩下一些技巧,可以使第二个文件中的数据适合该范围第一的数据。由于第一个的范围是splot,第二个的范围是plot,因此添加[10:25]很好。但是随后您必须“手动”生成关键帧,否则轮廓将被标记为[0.3:1.5]。这是更正的代码:

10

NB:

  1. 一个更清洁的解决方案是在两者上都使用10.3, 10.4,...并计算应向第二个文件中添加什么偏移量,而不是硬设置10。
  2. 从5.2版开始,您可以将reset set ztics 5 set zrange [10 : 25] #nowriteback set view 135,60 set contour base #surface set cntrlabel font ",7" set datafile missing "NaN" set clabel NSURFACES=1 #change if plotting more surfaces SHIFT=10 LEVELS="10.3, 10.4, 10.6, 11.0, 11.5" set cntrparam levels discrete @LEVELS set style line 100 lc rgb "white" splot 'out011_Io.txt' nonuniform matrix with lines notitle nocontour, \ 'out011_FlxN.txt' nonuniform matrix using 1:2:($3+SHIFT) with lines notitle enhanced nosurface, \ for [i=0:words(LEVELS)] 1/0 w l ls (i==0)?100:i+NSURFACES title (i==0)?"{/Symbol F}_{N}":sprintf(("%.1f"),word(LEVELS,i)-SHIFT) 替换为更干净的stats关键字。
相关问题