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

时间:2015-12-27 16:35:13

标签: gnuplot

我有下面的脚本,当我在第二个数据集中有第三列时,它可以正常工作。现在我想得到第一个直方图是用错误条绘制的,第二个是没有错误。我可以从第二个绘图命令中删除: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

1 个答案:

答案 0 :(得分:1)

我不确定是否可以这样做,但是您可以在没有错误栏的情况下绘制直方图,然后使用其他绘图命令添加它们。

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

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

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

Using histogram style

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

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

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

Using boxerrorbars and boxes

或者如果您需要将错误条设置为不同的颜色,请单独绘制

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

Using boxes and yerrorbars