【问题标题】:Adding vertical marker lines in gnuplot for histogram在 gnuplot 中为直方图添加垂直标记线
【发布时间】:2017-06-27 17:12:20
【问题描述】:

在绘制函数时,有一些说明可以在 gnuplot 中获取垂直线。就像使用 set arrow 函数一样。我需要直方图的这个功能,结果直方图在 X 轴上有不同的 0.0 位置。在我的情况下,X 轴标记只是数据文件中的字符串。

在绘制直方图时,如果能有平均值、+-3sigma 以及 X=0 点,则由绘图的顶部到底部以粗彩色实线标记的垂直线标记会非常好。

我的直方图代码:

set boxwidth 1.0 absolute
set style line 1 lc rgb 'skyblue'
set style fill solid border lt -1
set style data histogram
set style histogram clustered gap 0.0
set xtics in rotate by 90 offset first +0.5,0 right
set xlabel
set ylabel 'Count'
set terminal unknown
plot 'histo.raw' using 3
set title 'data'
set yrange [0:GPVAL_DATA_Y_MAX*1.2]
set term X11
plot 'histo.raw' using 3:xtic(2) ls 1 title columnheader(1)
set arrow 1 from 0.0,0.0 to 0.0,GPVAL_DATA_Y_MAX*1.2 nohead

我的数据:

"data"
     0 "-INF ->  -5.0"      0   0.00
     1 " -5.0 ->  -4.5"      0   0.00
     2 " -4.5 ->  -4.0"      2   0.03
     3 " -4.0 ->  -3.5"      4   0.06
     4 " -3.5 ->  -3.0"      3   0.05
     5 " -3.0 ->  -2.5"      5   0.08
     6 " -2.5 ->  -2.0"     19   0.30
     7 " -2.0 ->  -1.5"     49   0.78
     8 " -1.5 ->  -1.0"    193   3.07
     9 " -1.0 ->  -0.5"    527   8.39
    10 " -0.5 ->  +0.0"   1289  20.53
    11 " +0.0 ->  +0.5"   1878  29.90
    12 " +0.5 ->  +1.0"   1411  22.47
    13 " +1.0 ->  +1.5"    636  10.13
    14 " +1.5 ->  +2.0"    178   2.83
    15 " +2.0 ->  +2.5"     56   0.89
    16 " +2.5 ->  +3.0"     17   0.27
    17 " +3.0 ->  +3.5"      9   0.14
    18 " +3.5 ->  +4.0"      4   0.06
    19 " +4.0 ->  +4.5"      0   0.00
    20 " +4.5 ->  +5.0"      0   0.00
    21 " +5.0 -> +INF"      0   0.00

set arrow 函数将行放在错误的位置。

set arrow 1 from 0.0,0.0 to 0.0,GPVAL_DATA_Y_MAX*1.2 nohead

在这个数据中

mean= 0.2743
sigma= 0.7491

感谢您的想法。

格特

【问题讨论】:

    标签: gnuplot histogram


    【解决方案1】:

    我发现直方图条定义了它们自己的 X 坐标,从左到右计数。因为我有 22 个数据行,用于 22 个直方图条,将 11.0 添加到行位置就可以了。

    set boxwidth 1.0 absolute
    set style line 1 lc rgb 'skyblue'
    set style fill solid border lt -1
    set style data histogram
    set style histogram clustered gap 0.0
    set xtics in rotate by 90 offset first +0.5,0 right
    set xlabel
    set ylabel 'Count'
    set terminal unknown
    plot 'histo.raw' using 3
    set title 'data'
    set yrange [0:GPVAL_DATA_Y_MAX*1.2]
    set terminal png size 1200,800
    set output 'histo.png'
    mean= +0.2743
    sdev= +0.7491
    lboffs= 0.2
    set arrow  from 11.0 + mean,0.0 to 11.0 + mean ,GPVAL_DATA_Y_MAX*1.2 nohead lw 2 lc rgb "dark-green"
    set arrow  from 11.0 + mean - 3 * sdev,0.0 to 11.0 + mean - 3 * sdev ,GPVAL_DATA_Y_MAX*1.2 nohead lw 2 lc rgb "red"
    set arrow  from 11.0 + mean + 3 * sdev,0.0 to 11.0 + mean + 3 * sdev ,GPVAL_DATA_Y_MAX*1.2 nohead lw 2 lc rgb "red"
    set arrow  from 11.0,0.0 to 11.0,GPVAL_DATA_Y_MAX*1.2 nohead lw 2 lc rgb "blue"
    set label "Mean" at 11.0 + mean + lboffs,GPVAL_DATA_Y_MAX*1.1 tc rgb "dark-green"
    set label "+3%"  at 11.0 + mean + 3 * sdev + lboffs,GPVAL_DATA_Y_MAX*1.1 tc rgb "red"
    set label "-3%"  at 11.0 + mean - 3 * sdev + lboffs,GPVAL_DATA_Y_MAX*1.1 tc rgb "red"
    plot 'histo.raw' using 3:xtic(2) ls 1 title columnheader(1)
    set output
    set term X11
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多