【问题标题】:gnuplot: Row stacked bar graph with error bargnuplot:带误差线的行堆积条形图
【发布时间】:2014-03-21 02:16:38
【问题描述】:

我是 gnuplot 的新手。我想从具有三个分量和标准偏差的数据点生成图表。 我的数据如下所示:

TYPE1   15  20  65  5
TYPE2   20  20  60  4
TYPE3   10  30  60  6
TYPE4   30  30  40  5

我想为每种 TYPE 绘制一个行堆叠条,其中 3 个组件堆叠,顶部有一个错误条。 为此,我编写了以下脚本:

set terminal png
set output "sample.png"
set boxwidth 0.75 relative
set style fill   pattern 0 border
set style histogram rowstacked
set style data histograms
set xtics 1000 nomirror
set ytics 100 nomirror
set noytics
set mxtics 2
set mytics 2
set ytics 100
set yrange [0:150]
set ylabel "Y"
set xlabel "X"
set title "Sample graph"
plot 'data.dat' using (100*column(2)/(column(2)+column(3)+column(4))) t "A" , '' using (100*column(3)/(column(2)+column(3)+column(4))) t "B" , '' using (100*column(4)/(column(2)+column(3)+column(4))):xtic(1) t "C" 

这产生了一个如下所示的图表:。

但我无法在第 5 列中使用偏差值获得每个条形顶部的误差条。我尝试了使用 rowstacked 和 errorbar 样式条形图的不同方法,但没有运气。

【问题讨论】:

    标签: plot gnuplot histogram bar-chart


    【解决方案1】:

    为此,您必须知道,对于 histogram 样式,框被放置在 x 位置 0、1 等处,即在行号处。

    所以对于errorbars,您必须使用column(0) 作为x 坐标:

    set terminal pngcairo
    set output "sample.png"
    
    set boxwidth 0.75 relative
    set style fill pattern 0 border
    set style histogram rowstacked
    set style data histograms
    
    set yrange [0:150]
    
    set macros
    scale = '100/(column(2)+column(3)+column(4))'
    
    set bars 2.0
    plot 'data.dat' using ($2 * @scale):xtic(1) t "A" , \
         '' using ($3 * @scale) t "B" , \
         '' using ($4 * @scale) t "C",\
         '' using 0:(100):5 with errorbars notitle lw 2 lt -1
    

    4.6.3 的结果是:

    为方便起见,我使用了宏 scale。宏的工作方式如下:您在上面的脚本中定义一个字符串,如scale = '...'。以后可以在任何表达式中将其用作@scale(您必须启用set macros)。然后在执行相应的命令之前替换scale 字符串的内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-14
      • 1970-01-01
      • 1970-01-01
      • 2015-09-01
      • 1970-01-01
      • 2021-08-10
      • 1970-01-01
      相关资源
      最近更新 更多