首页 > 解决方案 > Gnuplot:带有仅包含 x 和 b(x) 的数据文件的 splot

问题描述

我想绘制以下函数的轮廓:

f(x,y)=y³*b(x)

我的数据文件看起来像这样:

  x         b(x)
-1         10.123
-0.995     10.112
-0.99      10.100

我不确定如何制作正确的 splot 命令,因为我的数据文件看起来不像 (xyz)。

到目前为止,这就是我的脚本:

reset
f(x,y)=y³*b(x)
set xrange [-6:6] 
set yrange [-5:5]
set isosamples 50
set table 'test.dat'
splot 'Data.dat' u 1:(b(x)=$2, f(x,y))     -------------------------?
unset table

set contour base
set cntrparam bspline
set cntrparam levels incremental -0.1,0.02,0.1
unset surface
set table 'contour.dat'
splot 'Data.dat' u 1:(b(x)=$2, f(x,y))      -------------------------?
unset table

reset 
set xrange [-6:6]
set yrange [-5:5]
unset key
set palette rgbformulae 33,13,10
plot 'test.dat' with image, 'contour.dat' w l lt -1 lw 1.5

标签: plotgnuplot

解决方案


直接从文件中的数据创建 3D 表面是行不通的,因为它们没有 y 坐标数据。该程序知道如何绘制数据并且知道如何绘制函数,但您必须选择其中一个。

要将绘图视为数据图,您需要扩展文件以包含 x/y/z 数据(请参阅“帮助矩阵”)。这可能在 gnuplot 之外更容易做到。

或者,您可以使用 gnuplot 的“fit”命令和您现有的数据文件,以某种分析形式重铸您的函数 b(x)。例如,假设对您的数据进行二次拟合就足够了:

b(x) = C0 + C1*x + C2*x*x + C3*x*x*x
C0=C1=1; C2=C3=0;
fit b(x) 'test.dat' using 1:2 via C0,C1,C2,C3

现在您有了要绘制轮廓的表面的 x 和 y 相关性的解析形式

f(x,y) = b(x) * y*y*y
set contour base
set cntrparam bspline
set cntrparam levels incremental -0.1,0.02,0.1
unset surface
splot f(x,y)

推荐阅读