【问题标题】:Plot a error bar as shaded region in GNUPLOT在 GNUPLOT 中将误差线绘制为阴影区域
【发布时间】:2020-06-20 20:22:12
【问题描述】:

我在 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(Error) 的示例数据

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

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

【问题讨论】:

  • 您的代码是/不完整,我猜在第一个绘图命令行中可能缺少using 1:3。你能检查并纠正吗?顺便说一句,您确定需要 10000x10000 像素分辨率吗?你想填满哪个区域? $2$3 之间的曲线?
  • 文件 MAN.outmd 有三列。 X 值、Y 值和 Z 标准误差。对于这个 XY 值,我想将误差绘制为阴影区域。
  • 什么是 Z 列,x-error 或 y-error?如果是 y 误差,你想如何对垂直线进行着色?如果是 x-error,你想如何对水平线进行着色?您能否提供一些示例数据?也许你真正想要的手绘草图?
  • @theozh 我已经编辑了我的问题。这是一个 x 错误

标签: gnuplot


【解决方案1】:

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

结果:

【讨论】:

    猜你喜欢
    • 2012-10-09
    • 2017-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-05
    • 2018-11-10
    • 1970-01-01
    相关资源
    最近更新 更多