在Gnuplot中的数据曲线下面填写几个部分

时间:2014-06-04 02:09:28

标签: gnuplot fill curves

我有一组点“数据”定义了一条曲线,我希望用贝塞尔曲线绘制。 所以我想在某些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

我意识到我的问题是,实际上我甚至不能填充一条曲线,它似乎被填充,因为那里的斜率几乎是恒定的。

1 个答案:

答案 0 :(得分:10)

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