【问题标题】:Clustered bar plot in gnuplot with errorbars带有误差条的gnuplot中的聚集条形图
【发布时间】:2017-06-16 00:15:42
【问题描述】:

我是使用 gnuplot 的新手,我关注了 this question,它可以根据需要绘制数据。但是,我非常想包括误差线。我尝试通过添加最小和最大错误列来做到这一点,如下所示:

Broswer,Video,min,max,Audio,min,max,Flash,min,max,HTML,min,max,JavaScript,min,max
IE,30%,5,5,10%,5,5,25%,5,5,20%,5,5,15%,5,5
Chrome,20%,5,5,5%,5,5,35%,5,5,30%,5,5,10%,5,5

然后我尝试使用修改如下的脚本进行绘图:

set terminal pdf enhanced
set output 'bar.pdf'

set style data histogram
set style histogram cluster gap 1

set style fill solid border rgb "black"
set auto x
set yrange [0:*]
set datafile separator ","

plot 'data.dat' using 2:xtic(1) title col with yerrorbars, \
        '' using 3:xtic(1) title col with yerrorbars, \
        '' using 4:xtic(1) title col with yerrorbars, \
        '' using 5:xtic(1) title col with yerrorbars, \
        '' using 6:xtic(1) title col with yerrorbars

据我了解,这也应该绘制错误栏,但我得到了错误:

“plot2”,第 16 行:此样式的列数不足

谷歌搜索这个错误告诉我它与第一列是非数字有关。我尝试了一些建议,包括this one,但到目前为止没有任何效果。那么,有什么建议吗?谢谢。

【问题讨论】:

    标签: gnuplot


    【解决方案1】:

    此错误告诉您,yerrorbars 绘图样式需要多列进行绘图(xtic(1) 采用特殊部分)。查看文档,您可以看到,您可以使用两列、三列或四列。我不会更详细地介绍,因为with yerrorbars 选择了一种全新的绘图样式,而您根本看不到任何直方图。

    为了绘制聚集直方图,你必须在直方图的样式定义中添加errorbars,当然你必须给出yerror值的列:

    set style data histogram
    set style histogram cluster gap 1 errorbars
    
    set style fill solid border rgb "black"
    set auto x
    set yrange [0:*]
    set datafile separator ","
    
    plot 'data.dat' using 2:3:xtic(1) title col(2),\
            '' using 5:6 title col(5), \
            '' using 8:9 title col(8), \
            '' using 11:12 title col(11), \
            '' using 14:15 title col(14)
    

    或者,简而言之

    plot for [i=2:14:3] 'data.dat' using i:i+1:xtic(1) title col(i)
    

    如果您明确需要绘制最小值和最大值,则必须添加第三列。但是最后两列是 ymin 和 ymax 而不是增量值。从你的数据文件错误来看,数据文件中的值是增量,所以 plot 命令应该是:

    plot for [i=2:14:3] 'data.dat' using i:(column(i) - column(i+1)):(column(i) + column(i+2)):xtic(1) title col(i)
    

    【讨论】:

    • 所以我猜不可能有带直方图的最小/最大误差线?谢谢。
    • 你可以,看我的更新。我不确定你是否真的需要明确的最小值和最大值,所以我首先有更简单的版本;)
    • 花了一些时间了解循环,但这是完美的。正是我需要的!!谢谢!!
    猜你喜欢
    • 1970-01-01
    • 2011-07-05
    • 2012-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多