【发布时间】:2021-04-13 00:35:38
【问题描述】:
我试图在矩形边界框内不“均匀”分布的数据上获取等高线。
为了得到这个,我需要玩几个技巧。
我必须unset dgrid3d,否则我无法按原样绘制数据。此外,当dgrid3d 关闭时,我必须将等高线绘制到表格中才能绘制等高线。
下面的代码有点麻烦,但如果等高线的水平正确,结果或多或少都可以。
在下面的示例中,它们的等级应该上升到 2500,而不仅仅是 1200。
代码:
### wrong contour line levels with "non-rectangular" data
reset session
# create some test data
set print $Data
do for [i=0:100] {
do for [j=0:100-i:5] {
print sprintf("%g %g %g",i,j,i*j)
}
print ""
}
set print
set pm3d
set view map
# get contour lines into table
set contour
set dgrid3d
set dgrid3d 20,20
set cntrparam levels auto 20
set table $Contour
splot $Data u 1:2:3
unset table
unset contour
unset dgrid3d
# only use the contourlines, skip grid data at index 0
set table $Contour2
splot $Contour u 1:2:3 index 1::1
unset table
# convert one empty line into two empty lines, otherwise splot will connect the lines
set print $Contour # overwrite datablock $Contour
do for [i=1:|$Contour2|] {
if ($Contour2[i] eq '') { print ""}
print $Contour2[i]
}
set print
stats $Contour2 u 0 nooutput # get number of blocks = number of contour lines
ContourLineCount = STATS_blocks
# get contour line values into array
array ContValues[ContourLineCount]
set table $Dummy
plot for [i=0:ContourLineCount-1] $Contour u (ContValues[i+1]=$3) index i every ::0::0 w table
unset table
set key noautotitle horizontal at screen 0.15,0.9
set size ratio -1
set lmargin screen 0.10
set rmargin screen 0.85
splot $Data u 1:2:3 w pm3d, \
for [i=0:ContourLineCount-1] $Contour u 1:2:3:3 index i w l lw 1.5 lc i, \
for [i=1:ContourLineCount] keyentry w l lw 1.5 lc i title sprintf("%g",ContValues[i])
### end of code
结果:
检查文档,我认为 gnuplot 需要在矩形边界框内或多或少均匀分布的数据。 所以,在上面的例子中,虽然等高线看起来有些合理,但层次却是无稽之谈。
来自help contour:
set contour 启用曲面的等高线绘制。这个选项是 仅适用于 splot。它需要网格数据,请参阅 grid_data 更多细节。如果需要非网格数据的等高线,请设置 dgrid3d 可用于创建适当的网格。
来自help dgrid3d:
启用后,从文件中读取的 3D 数据始终被视为 分散的数据集。具有从边界框派生的尺寸的网格 由 row/col_size 指定的分散数据和大小 为绘图和轮廓创建参数。格子是一样的 以 x(行)和 y(列)间隔; z 值计算为 散点z的加权平均值或样条插值 价值观。换句话说,创建了一个规则间隔的网格,并且 对所有网格点评估原始数据的平滑近似。 绘制此近似值以代替原始数据。
问题:
有没有办法获得正确的等高线水平?我认为我不能简单地将水平乘以 2 倍(这或多或少是预期水平)。也许镜像数据,获取级别并再次删除镜像数据?也许有人甚至可以简化代码以获得所需的结果?
【问题讨论】:
标签: gnuplot