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

弗朗西斯

我有一个数据集(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

在这里输入图像描述,我想绘制一个比较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 x1y1and axes x1y2由于您已明确指定y1和y2的范围,因此图框和标签不会受到影响。

  2. 但是,由于现在针对y1绘制了绿色条,因此我们必须对其进行缩放,以便应用y2轴标签。因此,第3列和第4列的值将除以26,即(y2范围)/(y1范围)

  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

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章