将错误栏绘制为GNUPLOT中的阴影区域

时间:2020-06-16 09:57:40

标签: gnuplot

我在Gnuplot中绘制了带有fsteps函数的图形(X轴,Y轴)。接下来,我尝试将错误栏添加为图形的阴影区域(透明),但无法在图形上绘制它。下面是到目前为止我尝试过的代码,并附上了图表。

#!/usr/bin/gnuplot
reset
set border lw 30
set term pngcairo size 10000,10000 font "arial-Bold,130"
set output 'out.png'
unset key
set size ratio 1.2
set style data lines
set xtics format ""
set x2tics nomirror
set ytics out nomirror
set ytics 0,20 
set x2label "Vs (km/s)" offset -1.0
set ylabel 'Depth (km)' offset 1.5
set xrange [2.5:4.8]
set yrange [314:0]
set label 3 at 2,120
set key samplen 1.7 at 3.0,135
#
set label 1 '(a)' font "arial-Bold,130" at 0.8,15 right 
set label 3 "C3 (MNAI)" center font "arial-Bold,130"
set style fill transparent solid 0.25
set style fill noborder

plot 'MAN.inmd' lc rgb 'blue' lw 35 title "Initial  model"   with fsteps,\
     'MAN.outmd' using 1:2 lc rgb 'red' lw 35  dt"-" title "Inverted model" with fsteps ,\
     'MAN.outmd' using 1:($2-$3):($2+$3) with filledcurve lc "blue" notitle, 

文件MAN.outmd X Y Z(错误)的示例数据

0        3         0
0.4475   3.1       0
0.4475   3.5       0
2.6738   3.6       0.0552
2.6738   5         0.0552
3.8441   5.1       0.0592
3.8441   8         0.0592
3.6302   8.1       0.0395
3.6302   15.935    0.0395
4.5176   15.1      0.041
4.5176   113.296   0.041
4.2443   113.3     0.1024
4.2443   214       0.1024
4.4584   214.1     0.1077
4.4584   314       0.1077

enter image description here

我希望输出如下所示(示例)

enter image description here

1 个答案:

答案 0 :(得分:0)

gnuplot可以轻松填充两条“水平”曲线(即唯一的x值)之间的区域,但据我所知,不能填充两条垂直曲线之间的区域。但是,gnuplot可以填充某些封闭区域。因此,解决方法是创建围绕要着色区域的数据点。为此,您可以将数据“绘制”到数据块中,一次使用x-dx“向前”,一次使用x+dx“向后”。如果您已经在数据块中添加了数据,则可以最轻松地完成此操作,因为这样您就可以轻松地前后循环数据。如果您将数据保存在文件中,请参见此处:gnuplot: load datafile 1:1 into datablock

代码:

### fill between vertical curves
reset session

$Data <<EOD
0        3         0
0.4475   3.1       0
0.4475   3.5       0
2.6738   3.6       0.0552
2.6738   5         0.0552
3.8441   5.1       0.0592
3.8441   8         0.0592
3.6302   8.1       0.0395
3.6302   15.935    0.0395
4.5176   15.1      0.041
4.5176   113.296   0.041
4.2443   113.3     0.1024
4.2443   214       0.1024
4.4584   214.1     0.1077
4.4584   314       0.1077
EOD

# create datablock with circumference of shaded area
set print $XErrorFill
    do for [i=1:|$Data|] {
        print real(word($Data[i],1))-real(word($Data[i],3)), real(word($Data[i],2))
    }
    do for [i=|$Data|:1:-1] {
        print real(word($Data[i],1))+real(word($Data[i],3)), real(word($Data[i],2))
    }
set print

set yrange [:] reverse
set style fill noborder

plot $XErrorFill u 1:2 w filledcurves lc "light-grey" notitle, \
     $Data u 1:2 w l lw 1.5 lc rgb "red" notitle
### end of code

结果:

enter image description here