【问题标题】:Gnuplot: How to add yerrorbars into a histogram that is plotted using "newhistogram" for several clustered histograms?Gnuplot:如何将 yerrorbars 添加到使用“newhistogram”绘制的几个聚集直方图的直方图中?
【发布时间】:2019-07-08 16:16:24
【问题描述】:

我已将一组聚类数据绘制到直方图的同一图中。由于我有几组数据,我使用了实用的“newhistogram”命令。效果很好,但我还没有找到如何添加 yerrorbars 呢?我很高兴有人熟悉如何将误差条添加到“新直方图”命令中。

我已经尝试添加简单命令“w yerrorbars”,包括对数据文件列的相关引用,但随后该图仅包含 yerrorbars(包括中间的平均值),但不再显示条形图。

...
set datafile separator ','
...
set style data histogram
set style histogram errobars linewidth 1
set bars 0.5

plot newhistogram "Multi-crew ops", 'example.dat' index 0 u 3:xtic(2) t 'Departure', 'example.dat' index 0 u 5:xtic(2) t 'Cruise', 'example.dat' index 0 u 7:xtic(2) t 'Arrival', \
    newhistogram "Reduced-crew ops", 'example.dat' index 1 u 3:xtic(2) t 'Departure', 'example.dat' index 1 u 5:xtic(2) t 'Cruise' , 'example.dat' index 1 u 7:xtic(2) t 'Arrival', \
    newhistogram "Acceptance of crewing-ops", 'example.dat' index 2 u 9:xtic(1) axes x1y2 t 'All phases'

这没有成功: ...

plot newhistogram "Multi-crew ops", 'example.dat' index 0 u 3:4:xtic(2) t 'Departure' w yerrorbars, ...

这也没有成功:

set datafile separator ','

set style data histogram
set bars 0.5
set style histogram errobars linewidth 1

plot newhistogram "Multi-crew ops", 'example.dat' index 0 u 3:4:xtic(2) t 'Departure', 'example.dat' index 0 u 5:6:xtic(2) t 'Cruise', 'example.dat' index 0 u 7:8:xtic(2) t 'Arrival', \
    newhistogram "Reduced-crew ops", 'example.dat' index 1 u 3:4:xtic(2) t 'Departure', 'example.dat' index 1 u 5:6:xtic(2) t 'Cruise' , 'example.dat' index 1 u 7:8:xtic(2) t 'Arrival', \
    newhistogram "Acceptance of crewing-ops", 'example.dat' index 2 u 9:10:xtic(1) axes x1y2 t 'All phases'

【问题讨论】:

    标签: gnuplot bar-chart histogram errorbar


    【解决方案1】:

    您显示的命令的问题是每个条形图只提供一列输入数据(y 值)。为了添加误差线,您需要第二个输入列来保存 delta-y 值。例如你有

       'example.dat' index 0 u 3:xtic(2) t 'Departure'
    

    你应该有

       'example.dat' index 0 u 3:N:xtic(2) t 'Departure'
    

    其中 N 是保存错误值的列。如果要从函数计算错误而不是从输入列中读取错误,它看起来像这样

       'example.dat' index 0 u 3:(func(something)):xtic(2) t 'Departure'
    

    【讨论】:

    • (1) 有一个错字:'errobars' 而不是 'errorbars' (2) 这是因为(1)中的命令被拒绝了,所以样式没有设置为errorbars。跨度>
    • 好的,这也行得通。谢谢。因此,newhistogram 可以与所有常用的 gnuplot 命令结合使用。
    【解决方案2】:

    最后,我找到了如何将误差线集成到 gnuplot 的 newhistogram 命令中的答案。样式必须设置为 histogram cluster。甚至可以调整颜色等:

    ...
    set style histogram cluster gap 2 errorbars linewidth 2
    set style data histogram
    ...
    plot newhistogram "condition 1", 'example.dat' index 0 u 3:4:xtic(2) t 'Departure' lw 2 lc rgb "#32CD32", 'example.dat' index 0 u 5:6:xtic(2) t 'Cruise' lw 2 lc rgb "#6745FF", 'example.dat' index 0 u 7:8:xtic(2) t 'Arrival' lw 2 lc rgb "#FFA057", \
        newhistogram "condition 2", 'example.dat' index 1 u 3:4:xtic(2) lw 2 lc rgb "#32CD32" notitle, 'example.dat' index 1 u 5:6:xtic(2) lw 2 lc rgb "#6745FF" notitle, 'example.dat' index 1 u 7:8:xtic(2) lw 2 lc rgb "#FFA057" notitle, \
        newhistogram "condition 3", 'example.dat' index 2 u 9:10:xtic(1) axes x1y2 t 'All phases' lw 2 lc rgb "#A19CB8"
    

    【讨论】:

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