【问题标题】:Show error bars in a multiaxis plot in Gnuplot在 Gnuplot 的多轴图中显示误差线
【发布时间】:2021-01-15 01:22:14
【问题描述】:

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

型号#DE IE 错误

苹果 -4.6 -128.9538 4.0

华为 -5.2 -176.6343 5.3

One-Pro -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 列中的数据)。

请大家帮忙看看怎么做。

【问题讨论】:

    标签: gnuplot histogram errorbar


    【解决方案1】:

    有一个变体直方图样式正是为了这个目的 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 range) / (y1 range)

    3. 在“直方图误差线”模式下,每个绘图组件都会查找额外的数据列来确定误差线的大小。由于您的第 2 列数据没有相应的错误列,我们将其虚拟化以使用所有常量非数字(无数据)值:(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 ($3/26.):($4/26.):xticlabels(1) ti 'IE' lc 4
    

    【讨论】:

    • 嗨,Ethan,你能详细解释一下吗?
    • 嗨@Ethan,我尝试了新的绘图命令,它似乎已经通过误差线偏移了。
    • 嗨@Ethan,我尝试了新的绘图命令,它似乎工作但误差线偏移。 imgur.com/lKcnVlH
    • 我在第一次尝试时也得到了偏移量。那时我意识到数据文件中存在额外的一行导致了混乱。添加set key autotitle columnhead 修复了偏移量。
    • 终于成功了。我去掉了数据文件中多余的行。imgur.com/ZXekOAd 谢谢@Ethan。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多