gnuplot - 绘制两个直方图,一张图中有误差线,一张没有误差线

标签 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

最佳答案

我不确定通常是否可以这样做,但您可以绘制没有误差线的直方图,然后使用附加绘图命令添加它们。

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 轴值)。

对于您的示例,我建议使用框和 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

关于gnuplot - 绘制两个直方图,一张图中有误差线,一张没有误差线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34482441/

相关文章:

text - 是否可以设置标签相对于 gnuplot 中的键的位置?

Haskell Array.Accelerate - forkOS 错误

ubuntu - 如何对日期数据执行指数拟合?

rotation - gnuplot 旋转轴标签(xlabel、ylabel 和 zlabel)在 3d 图中不起作用

plot - 等高线之间具有恒定颜色的填充等高线图

gnuplot - 将轴视为日期/时间(纪元)

c - Gnuplot 和 C "x range is invalid"

gnuplot - 在 dgrid3d 和 pm3d 上画一条线

gnuplot - 如何在gnuplot中计算横坐标平均值来绘制图形

gnuplot - 合并多个数据文件以绘制在单个图表中