如何在 gnuplot 中创建自定义填充样式?

How to create custom filling style in gnuplot?

基本上我想在 gnuplot 中重现下图中的填充样式:

我尝试使用带填充曲线的常见图案,但 none 的图案与图片中的相似。有没有办法在 gnuplot 中获得这种类型的 patterns(注意填充区域是 not solid)? 谢谢。

勾选help filledcurves,根据方案0xAARRGGBB设置颜色为透明。

代码:

### semitransparent fill between curves
reset session

# create some random test data
set print $Data1
    do for [x=1:100] { print sprintf("%g %g %g %g",x,5*cos(x/7.)+rand(0),rand(0)+0.3,rand(0)+0.3) }
set print
set print $Data2
    do for [x=1:100] { print sprintf("%g %g %g %g",x,3*sin(x/9.)+rand(0),rand(0)+0.3,rand(0)+0.3) }
set print
unset key

plot $Data1 u 1:2 w l lc "red", \
     ''    u 1:(-):(+) w filledcurve lc rgb 0xeeff0000, \
     $Data2 u 1:2 w l lc "blue", \
     ''    u 1:(-):(+) w filledcurve lc rgb 0xee0000ff
### end of code

结果:

添加:(垂直虚线“填充”的解决方法)

老实说,(就像你的情况一样)如果你必须放大到非常近的距离才能看到半透明填充和垂直线“填充”之间的区别,那么我不确定这是否真的必要的。

无论如何,这里有一个“填充”垂直虚线的解决方法。这是实现 with vectors 和虚线 dt 1(=实线),dt 2(=虚线),dt 3(=虚线)。然而,这不是真正的填充,而是需要足够的常规(此处:1000)数据点才能给人以这种印象。它还取决于线条颜色的透明度和图形的大小。如果您没有足够的常规数据点,您可以对数据重新采样,但是,这在 gnuplot 中并不简单(参见:Resampling data with gnuplot),

这看起来仍然与您的示例不一样,但更接近了。

代码:

### special "fill" with dashed vertical lines
reset session

# create some random test data
set table $Data1
    set samples 1000
    plot [1:100] '+' u (x):(3*cos(x/5.)):(rand(0)*0.5+0.3):(rand(0)*0.5+0.3) w table
set table $Data2
    set samples 1000
    plot [1:100] '+' u (x):(5*sin(x/7.)):(rand(0)*0.5+0.3):(rand(0)*0.5+0.3) w table
set table $Data3
    set samples 1000
    plot [1:100] '+' u (x):(7*sin(x/9.)):(rand(0)*0.5+0.3):(rand(0)*0.5+0.3) w table
unset table

unset key
plot $Data1 u 1:2 w l lc "red", \
     ''    u 1:(-):(0):(1) w vectors lc rgb 0xddff0000 dt 1 nohead, \
     $Data2 u 1:2 w l lc "green", \
     ''    u 1:(-):(0):(+) w vectors lc rgb 0xdd00ff00 dt 2 nohead, \
     $Data3 u 1:2 w l lc "blue", \
     ''    u 1:(-):(0):(+) w vectors lc rgb 0xdd0000ff dt 3 nohead 
### end of code

结果:

放大显示虚线: