从两个带有 Gnuplot 错误栏的文件中绘制

Plot from two files with errorbars for Gnuplot

我正在考虑通过考虑数据格式来更好地添加错误栏的方法。 例如,讨论了添加错误栏的标准方法 here

我的原始数据在范围内

Model Decreasing Constant Increasing 
2025 73-78 80-85 87-92 
2035 63-68 80-85 97-107 
2050 42-57 75-90 104.5-119.5 

其中值是范围。 我不能直接在 Gnuplot 中绘图,所以我必须将它拆分为两个文件中的平均值和错误值:

平均值:

Model Decreasing Constant Increasing
2025 75.5 82.5 89.5
2035 65.5 82.5 102
2050 49.5 82.5 112

ybar配置错误

Model Decreasing Constant Increasing
2025 2.5 2.5 2.5
2035 2.5 2.5 5
2050 7.5 7.5 7.5

我通常将这样的数据绘制成一个文件

plot for [i=2:4] 'data.dat' using 1:i w linespoints

但现在我应该在做剧情的时候同时浏览两个文件。 绘制误差线的正常语法是

plot 'data' using 1:2:0:(+):4:5 with yerrorlines

和手动 here

如何在 Gnuplot 中从两个带有错误条的文件中绘图? 如果您知道在 gnuplot 中添加这些错误栏的更好方法,请随时提出建议。

输出到 Cristoph 的回答

第一点和第三点缺少误差线。

首先,我想知道您用于绘图的列 with yerrorlines。如果你 2025 年的第一个数据是 75.5+/-2.5,你通常用

绘制它
plot "datafile" using <xcolum>:<ycolum>:<yerrorcolumn>

您的六列用于 xy 误差条的情况,并指定点本身以及 x 和 y 中的上下绝对值。但也许您只是在需要时才这样做...

现在回到你的问题: Gnuplot 可以不能同时处理来自两个文件的数据,即它不能从一个文件中获取 xy 值而从另一个文件中获取 y 错误。

如果您是 运行 linux,命令行工具 join 可以提供帮助。 您存储在文件 A 中的平均值和文件 B 中的错误 join A B 将在第一列中连接具有相同值的行,如下所示:

2025 75.5 82.5 89.5 2.5 2.5 2.5

所以,

plot "<join A B" using 1:2:5 with yerrorlines

应该完成这项工作。 ("<join A B"会在后台调用join命令,像读取数据文件一样读取它的输出)

Gnuplot 5 支持指定多个字符作为数据文件分隔符。

因此,如果您确定永远不会得到负值(考虑到您的数据格式,我希望如此),那么您可以使用原始数据文件并将白色 space 和连字符设置为数据文件分隔符:

set datafile separator " -"
plot for [i=2:6:2] "data" using 1:(0.5*(column(i)+column(i+1))):(0.5*(column(i+1)-column(i))) with yerrorlines