如何将平滑的cspline曲线输出为数据文件

15

有人知道如何从给定数据中提取平滑cspline曲线的一些数据吗?

例如,有一个数据文件,它有2列对应于x和y值。我可以通过以下命令绘制具有平滑cpline曲线的数据

p 'data' w lp, ""  smooth csplines

我希望能将光滑的cpline曲线提取为另一个数据文件。

2个回答

13
这可以通过设置一个表格来完成。考虑以下数据文件:
0 1
1 2
2 3
3 2
4 2
5 4
6 8
7 5
8 3
9 1

数据本身及其csplines插值如下所示:

enter image description here

要将插值打印到表格中,请执行以下操作:
set samples 100
set table "table_100"
plot "data" smooth csplines
set samples 20
set table "table_20"
plot "data" smooth csplines
unset table

set samples 确定用于构建样条曲线的点数。您可以进行可视化:

set key left
plot "data" pt 7 t "Original data", \
     "table_100" w l t "Splines (100 samples)", \
     "table_20" w l t "Splines (20 samples)"

enter image description here


6

使用set table 'temp.dat'将绘制的数据点重定向到外部文件。

set table 'temp.dat'
plot 'myfile.dat' using 1:2 smooth cspline
unset table

为了测试它。
plot 'myfile.dat' using 1:2 with points title 'original points',\
     'temp.dat' using 1:2 with lines title 'smoothed curve'

糟糕的同步 :-D 当你发布这个问题时,我正在写我的答案。不可能赢过你! - Miguel
@Miguel :) 抱歉,我认为我应该退后一点,以免分散其他回答者的注意力...很好,你在你的回答中添加了一些例子。我一直在寻找一个重复的问题,但没有找到合适的。现在我们有了你的答案作为很好的参考。 - Christoph
好吧,至少有gnuplot标签,有机会回答。试着做第一个回答Python问题的人吧…… - Miguel
有人知道如何重叠“点”和“线”在图例中,这样我就可以得到一个单一的图例条目,而不是同一数据的两个不同条目吗? - Sufyan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接