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

example of what I want to do

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

编辑:最小工作示例:

#!/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

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

有帮助吗?

解决方案

要填充曲线下方的部分,必须使用 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):

enter image description here

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

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'
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top