在一个图中绘制两个直方图,一个 w/ 和一个 w/o 误差条

plotting two histograms, one w/ and one w/o error bars in one plot

我有下面的脚本,当我在第二个数据集中有第三列时它工作正常。现在我想要绘制第一个带有误差线的直方图,以及第二个 w/o。我可以从第二个 plot 命令中删除 :3 但 gnuplot 会抱怨没有为第二个直方图指定足够的数据。如果我删除 set style histogram errorbars ... 但这也会禁用第一个直方图上的误差线。有没有办法在同一个图中绘制两个直方图,其中一个没有误差线。

set xlabel ""
set ylabel ""
set boxwidth 0.9 absolute
set style fill solid 1.00 border -1
set style histogram errorbars gap 1
set style data histograms
set yrange [-1.746917959031165368e-01:3.668527713965446857e+00]
unset key
set datafile commentschar "#"
plot '-' using 2:3:xtic(1) title "onehist",\
'-' using 2:3:xtic(1) title "otherhist"
-3.583733737468719482e-01 1.073847990483045578e-02 1.073847990483045578e-02
-3.382162153720855713e-01 2.274234220385551453e-02 1.329828426241874695e-02
2.261839509010314941e-01 2.859487235546112061e-01 8.173441886901855469e-02
e
-1.164875924587249756e-01 4.266476333141326904e-01
-9.633044153451919556e-02 5.953223109245300293e-01
-7.617329061031341553e-02 6.151663661003112793e-01
-5.601614341139793396e-02 9.624376893043518066e-01
e

我不确定一般情况下是否可以这样做,但您可以绘制不带误差线的直方图,然后使用额外的绘图命令添加它们。

plot '-' using 2:xtic(1) title 'onehist',\ 
'-' using ([=10=]-0.2):2:3 with yerrorbars lc 'black' pt 0, \
'-' using 2:xtic(1) title 'otherhist',\ 

我不完全确定如何确定实际条形的范围,因此误差条没有完全居中,但这会按要求将它们放在图表上。

附加命令使用 yerrorbars 样式(这是直方图条的绘制方式)来绘制误差条。

但是,这并不是绘制直方图的最佳方式。 Gnuplot 会将 x-axis 视为具有值 0、1、2、3 等的类别。因此,即使您在上面的两个列表中具有不同的 x 值,它们也会相互叠加(并且第二个图将更改第一个设置的 x-axis 值。

对于您的示例,我建议使用 boxes 和 boxerrorbars 样式。

set style fill solid
set boxwidth 0.01
plot '-' using 1:2:3 with boxerrorbars, '-' u 1:2 with boxes

或者如果您需要将误差线设为不同的颜色,请单独绘制它们

plot '-' using 1:2 with boxes,\ 
'-' using 1:2:3 with yerrorbars lc 'black' pt 0,\
'-' u 1:2 with boxes