【问题标题】:gnuplot: How can I add error bars that start at 0?gnuplot:如何添加从 0 开始的误差线?
【发布时间】:2020-03-21 23:42:13
【问题描述】:

我想在我的直方图中添加从 0 开始的误差线。

this 和 this 之类的示例都从条形图的峰值开始。

这就是我目前制作条形图的方式:

set style histogram clustered

unset title
set xlabel "X"
set ylabel "Y"
set boxwidth 1
set style fill solid
set term png
set output "figure.png"

plot [-0.5:4.5][0:10] "data.dat"using 2:xtic(1) title "Title 1" with histograms fillstyle pattern 1, \
    "" using 3 title "Title 2" with histograms fillstyle pattern 2, \
    "" using 4 title "Title 3" with histograms fillstyle pattern 3

我可以在我的 data.dat 文件中添加第 4 列,其中包含误差线的高度,但我不知道绘制它的正确方法。

编辑:

set style fill solid 1.0
w = 0.15
set boxwidth 0.3
set key top right

set xlabel "X"
set ylabel "Y"
set xrange[0.5:5.9]
set yrange[0:300]
set xtics 1

plot "data.dat" u ($1-w):2 w boxes lc rgb "read" ti "Title 1", \
     '' u ($1+w):3 w boxes lc rgb "green" ti "Title 2", \
     '' u ($1+w*3):4 w boxes lc rgb "blue" ti "Title 3", \
     '' u ($1-w):5 w impulses dt 3 lw 3 lc rgb "black" ti "Title 4", \
     '' u ($1-w):5 w p pt 7 ps 1 lc rgb "black" not, \
     '' u ($1+w):6 w impulses dt 3 lw 3 lc rgb "black" not, \
     '' u ($1+w):6 w p pt 7 ps 1 lc rgb "black" not, \
     '' u ($1+w*3):7 w impulses dt 3 lw 3 lc rgb "black" not, \
     '' u ($1+w*3):7 w p pt 7 ps 1 lc rgb "black" not, \
     '' u 0:(NaN):xtic(1) not

【问题讨论】:

    标签: gnuplot


    【解决方案1】:

    为什么不“手动”绘制它with boxes 和 with impulses 和 with points?你没有提供示例数据,所以我创建了一些数据。 比如像这样。也许有更短的方法。

    编辑:使用 xtic 字符串而不是数字。

    代码:

    ### manual histogram and percentile line
    reset session
    
    # n MedianX MedianY  Perc90x  Perc90y
    $Data <<EOD
      A     7.1     6.2     20.3     16.4
      B     8.1     7.2     22.3     17.4
      C     9.1     8.2     24.3     18.4
      D    10.1     9.2     26.3     19.4
      E    11.1    10.2     28.3     20.4
    EOD
    
    set style fill solid 1.0
    w = 0.15
    set boxwidth 0.3
    set key top left
    set xrange[-0.5:4.5]
    set xtics 1
    
    plot $Data u ($0-w):2 w boxes lc rgb "red" ti "Median x", \
         '' u ($0+w):3 w boxes lc rgb "blue" ti "Median y", \
         '' u ($0-w):4 w impulses dt 3 lc rgb "black" ti "90th Percentile", \
         '' u ($0-w):4 w p pt 7 ps 1 lc rgb "black" not, \
         '' u ($0+w):5 w impulses dt 3 lc rgb "black" not, \
         '' u ($0+w):5 w p pt 7 ps 1 lc rgb "black" not, \
         '' u 0:(NaN):xtic(1) not
    ### end of code
    

    结果:

    添加:(用于 3 列和 with errorlines 而不是 impulses 和 points)

    代码:

    ### manual histogram and percentile line
    reset session
    
    # n MedianX MedianY MedianZ  Perc90x  Perc90y  Perc90z
    $Data <<EOD                                  
      A     7.1     6.2     5.3     20.4     16.5     12.6
      B     8.1     7.2     6.3     22.4     17.5     13.6
      C     9.1     8.2     7.3     24.4     18.5     14.6
      D    10.1     9.2     8.3     26.4     19.5     15.6
      E    11.1    10.2     9.3     28.4     20.5     16.6
    EOD
    
    set style fill solid 1.0
    w = 0.20
    set boxwidth 0.20
    set key top left
    set xrange[-0.5:4.5]
    set xtics 1
    
    plot $Data u ($0-w):2 w boxes lc rgb "red" ti "Median x", \
         '' u ($0):3 w boxes lc rgb "blue" ti "Median y", \
         '' u ($0+w):4 w boxes lc rgb "web-green" ti "Median z", \
         '' u ($0-w):(0):(0):5 w errorlines ls 0 ti "90th Percentile", \
         '' u ($0):(0):(0):6 w errorlines ls 0 not, \
         '' u ($0+w):(0):(0):7 w errorlines ls 0 not, \
         '' u 0:(NaN):xtic(1) not, \
    ### end of code
    

    结果:

    【讨论】:

    • 你能告诉我如何在 xtics 中使用字母而不是数字吗?我厌倦了在数据文件中更改它们,但没有任何绘图。
    • 那么你必须使用$0作为x坐标(见help pseudocolumns)并使用另一个绘图命令来获取(未移位的)xtic标签。我修改了代码。我希望这能完全回答您的问题。
    • 我尝试修改您的代码以使用 3 列。我得到了工作的冲动和酒吧,但我无法让 xtics 正确绘制。当我在 data.dat 文件中将数字更改为字母时,它只绘制 B、C、D、E 并且没有条形或脉冲。
    • 如果我没有看到您的实际代码,这很难说。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-05
    • 1970-01-01
    • 1970-01-01
    • 2021-01-25
    • 2014-07-08
    • 1970-01-01
    相关资源
    最近更新 更多