3

我有一组点“数据”定义了一条我想用贝塞尔曲线平滑绘制的曲线。所以我想在一些 x 值对之间填充该曲线下方的区域。如果我只有一对 x 值,那并不难,因为我定义了一组新数据并用 Filledcu 绘制它。例子:

我想做的例子

问题是我想在同一个情节中多次这样做。

编辑:最小的工作示例:

#!/usr/bin/gnuplot
set terminal wxt enhanced font 'Verdana,12'

set style fill transparent solid 0.35 noborder
plot 'data' using 1:2 smooth sbezier with lines ls 1
pause -1

“数据”的结构是:

x_point y_point

我意识到我的问题是事实上我什至无法填充一条曲线,它似乎被填充了,因为那里的斜率几乎是恒定的。

4

1 回答 1

12

要填充曲线下方的部分,您必须使用filledcurves样式。使用该选项x1填充曲线和 x 轴之间的部分。

为了只填充曲线的一部分,您必须过滤数据,即如果 x 值1/0超出所需范围,则为(无效数据点)值,否则为数据文件中的正确值。最后绘制曲线本身:

set style fill transparent solid 0.35 noborder
filter(x,min,max) = (x > min && x < max) ? x : 1/0
plot 'data' using (filter($1, -1, -0.5)):2 with filledcurves x1 lt 1 notitle,\
     ''  using (filter($1, 0.2, 0.8)):2 with filledcurves x1 lt 1 notitle,\
     ''  using 1:2 with lines lw 3 lt 1 title 'curve'

这填充了范围[-1:0.5][0.2:0.8]

举一个工作示例,我使用特殊的文件名+

set samples 100
set xrange [-2:2]
f(x) = -x**2 + 4

set linetype 1 lc rgb '#A3001E'

set style fill transparent solid 0.35 noborder
filter(x,min,max) = (x > min && x < max) ? x : 1/0
plot '+' using (filter($1, -1, -0.5)):(f($1)) with filledcurves x1 lt 1 notitle,\
     ''  using (filter($1, 0.2, 0.8)):(f($1)) with filledcurves x1 lt 1 notitle,\
     ''  using 1:(f($1)) with lines lw 3 lt 1 title 'curve'

结果(4.6.4):

在此处输入图像描述

如果您必须使用某种平滑,过滤器可能会对数据曲线产生不同的影响,具体取决于过滤的部分。您可以先将平滑数据写入临时文件,然后将其用于“正常”绘图:

set table 'data-smoothed'
plot 'data' using 1:2 smooth bezier
unset table

set style fill transparent solid 0.35 noborder
filter(x,min,max) = (x > min && x < max) ? x : 1/0
plot 'data-smoothed' using (filter($1, -1, -0.5)):2 with filledcurves x1 lt 1 notitle,\
     ''  using (filter($1, 0.2, 0.8)):2 with filledcurves x1 lt 1 notitle,\
     ''  using 1:2 with lines lw 3 lt 1 title 'curve'
于 2014-06-04T07:16:29.890 回答