在Gnuplot中的数据曲线下方填充几个部分 [英] Fill several sections below a curve of data in Gnuplot

查看:198
本文介绍了在Gnuplot中的数据曲线下方填充几个部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组点数据,它们定义了一条我想用贝塞尔曲线平滑绘制的曲线。
因此,我想填充一些x值对之间的那条曲线下方的区域。
如果我只有一对x值,那并不难,因为我定义了一组新数据并用fillcu进行绘制。示例:

I have a set of points "data" defining a curve that I want to plot with bezier smooth. So I want to fill the area below that curve between some pairs of x values. If I only had one pair of x values it's not that difficult because I define a new set of data and plot it with filledcu. Example:

问题是我想在同一图中多次执行该操作。

The problem is that I want to do that several times in the same plot.

编辑:最小的工作示例:

Minimal working example:

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

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

And I realized that my problem is that in fact I can't fill not even one curve, it seems to be filled because the slope is almost constant there.

推荐答案

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

To fill parts below a curve, you must use the filledcurves style. With the option x1 you fill the part between the curve and the x-axis.

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

In order to fill only parts of the curve, you must filter your data, i.e. give the x-values a value of 1/0 (invalid data point) if they are outside of the desired range, and the correct value from the data file otherwise. At the end you plot the curve itself:

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]

举一个有效的例子,我使用特殊的文件名 +

To give a working example, I use the special filename +:

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):

With the result (with 4.6.4):

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

If you must use some kind of smoothing, the filter may affect the data curve differently, depending on the filtered part. You can first write the smoothed data to a temporary file and then use this for 'normal' plotting:

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'

这篇关于在Gnuplot中的数据曲线下方填充几个部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆