在 Gnuplot 的多轴图中显示误差线

Show error bars in a multiaxis plot in Gnuplot

我有一个数据集 (show-errorbar.dat) 包含:

型号# DE IE 错误

苹果-4.6 -128.9538 4.0

华为-5.2 -176.6343 5.3

一临-5.2 -118.1106 3.2

#!/usr/bin/gnuplot
#set terminal pdfcairo enhanced color font 'Helvetica,12' linewidth 0.8
set terminal png
set output 'BrandError.png'

set boxwidth 1.0 relative
set bmargin 5
set style fill solid border -1
set xtic rotate by -45 scale 0
#set auto x

set style line 81 lt 0 lc rgb "#808080" lw 0.5

set grid xtics
set grid ytics
set grid mxtics
set grid mytics
set grid back ls 81

set arrow from graph 0,first -4.6 to graph 1, first -4.6 nohead lw 2 lc rgb "#000000" front

set border 11
set border lw 2.0

set xtics font ",11"
set ytics font ",14"
set tics out
set ytics nomirror
set y2tics
set y2tics font ",14"


set mxtics 10
set mytics 2
set my2tics 2

set yrange [-10:0]
set y2range [-260:0]

set key left bottom

set y2label offset -2
set ylabel offset 2

set ylabel 'DE' tc rgb "red"
set y2label 'IE' tc rgb "green"

set style data histograms
set style histogram cluster gap 2

set linetype 2 lc rgb 'red'
set linetype 3 lc rgb 'yellow'
set linetype 4 lc rgb 'green'


plot 'show-errorbars.dat' using 2 ti 'DE' lc 2 axis x1y1, '' u 3:xticlabels(1) ti 'IE' lc 4 axis x1y2
set output

enter image description here 我想绘制比较 DE 与 IE 的直方图 并显示 IE 值的误差线(第 4 列中的数据)。

请大家帮忙解决一下。

有一个变体直方图样式正是为了这个目的 set style histogram errorbars gap 2 {lw W}。 这是文档的帮助部分:

The `errorbars` style is very similar to the `clustered` style, except that it
requires additional columns of input for each entry. The first column holds
the height (y value) of that box, exactly as for the `clustered` style.
      2 columns:        y yerr          bar extends from y-yerr to y+err
      3 columns:        y ymin ymax     bar extends from ymin to ymax
The appearance of the error bars is controlled by the current value of
`set errorbars` and by the optional <linewidth> specification.

更新答案

备注:

  1. 您不能在单个直方图中混合选择轴。所以我从 plot 命令中删除了 axes x1y1axes x1y2 。由于您已明确指定 y1 和 y2 的范围,因此绘图边框和标签不受影响。

  2. 然而,由于绿色条现在是根据 y1 绘制的,我们必须缩放它们以便应用 y2 轴标签。所以第3列和第4列的值将除以26,即(y2范围)/(y1范围)

  3. 在“直方图误差线”模式下,每个绘图组件都会查找额外的数据列以确定误差线的大小。由于您的第 2 列数据没有相应的错误列,我们将其虚拟化以使用所有常量 not-a-number(无数据)值:(NaN)

  4. 您的数据包含一行列标题,如果程序认为这是一行数据,它可能会混淆。您可以通过多种方式告诉程序跳过这一行;为方便起见,我使用了 set key autotitle columnhead,因为旧版本的 gnuplot 支持它。如果您有当前版本,最好使用 set datafile columnheaders.

除了 plot 命令被以下 3 行替换之外,我保留了您的所有命令:

set style histogram errorbars gap 2 lw 1.5
set key autotitle columnhead

plot 'show-errorbars.dat' using 2:(NaN) ti 'DE' lc 2, '' u (/26.):(/26.):xticlabels(1) ti 'IE' lc 4