gnuplot:如何使用“获取正确的等高线标高值”;“不均匀”;数据?
我试图在矩形边界框内“均匀”分布的数据上获得轮廓线。 为了得到这个,我需要玩几个把戏。 我必须gnuplot:如何使用“获取正确的等高线标高值”;“不均匀”;数据?,gnuplot,Gnuplot,我试图在矩形边界框内“均匀”分布的数据上获得轮廓线。 为了得到这个,我需要玩几个把戏。 我必须取消设置dgrid3d,否则无法按原样绘制数据。此外,我必须将等高线绘制到表格中,以便在禁用dgrid3d时绘制等高线。 下面的代码有点麻烦,但是如果等高线的级别正确的话,结果或多或少是可以的。 在下面的例子中,他们的水平应该上升到2500,而不仅仅是1200 代码: ### wrong contour line levels with "non-rectangular" data
取消设置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
结果:
### 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需要在矩形边界框中或多或少地均匀分布数据。
所以,在上面的例子中,虽然等高线看起来有点合理,但是水平线是毫无意义的
从帮助轮廓
:
“设置轮廓”启用曲面的轮廓绘制。这个选项是
仅适用于splot。它需要网格数据,有关详细信息,请参见网格数据
更多细节。如果需要来自非栅格数据的等高线,请设置dgrid3d
可用于创建适当的网格
从帮助dgrid3d
:
启用时,从文件读取的三维数据始终被视为
分散的数据集。具有从边界框导出的尺寸的栅格
行/列大小指定的分散数据和大小
将创建用于打印和轮廓绘制的参数。网格是相等的
以x(行)和y(列)间隔;z值计算如下:
散乱点z的加权平均或样条插值
价值观换句话说,将创建一个规则间隔的栅格,并且
对所有网格点计算原始数据的平滑近似。
绘制此近似值以代替原始数据
问题:
### 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
是否有可能获得正确的等高线水平?我不认为我可以简单地将水平乘以2(这或多或少是预期水平)。可能是镜像数据、获取级别并再次删除镜像数据?也许有人甚至可以简化代码以获得所需的结果?我认为所有这些额外的步骤来调整数据格式和创建单独的等高线数据块是完全不必要的 这里的根本问题是,您的数据不仅仅是“不均匀的”;它的密度超过了正在绘制的一半区域,但另一半区域完全缺失。没有任何数据的区域的“正确等高线”是什么 你需要的是
# 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)
}
}
unset print
set dgrid3d 20,20 gauss
set view map
set size ratio -1
set key outside
set contour
set cntrparam levels auto 20
set cntrlabel format "%.0f"
set obj 1 polygon from graph 0,1 to graph 1,1 to graph 1,0
set obj 1 front fillstyle solid noborder fillcolor "white"
splot $Data u 1:2:3 w lines nosurface title '$Data'
谢谢你的建议。用白色多边形覆盖数据是一种解决方法。我想以某种方式剪切数据。我将检查如何将其与pm3d绘图结合起来,并让您知道。另一种可能会很复杂,并且需要更多关于数据所涵盖领域的知识:变换原始[x,y]坐标的轴,以便数据在变换后的坐标空间中占据矩形。使用
设置非线性
为逆变换定义gnuplot的x/y轴。等高线和绘图正常。