【问题标题】:Making Histograms with GNUPlot使用 GNUPlot 制作直方图
【发布时间】:2013-10-28 03:15:15
【问题描述】:

我想使用第 1,2 和 1,3 列从一个数据文件中制作两个比较直方图。

(数据文件名为“Cumulos por Edades.tab”)

6.25   46   60
6.75   29   65
7.25   79   70
7.75   87   75
8.25   80   80
8.75   41   84
9.25   28   89
9.75   13   94

我已经能够做出一些事情,但不是我想要的。这是代码。

(抱歉,我无法上传结果图片)

set terminal postscript enhanced color dashed lw 2 "Helvetica" 14
set output "Histograma.ps"
set key horizontal below height 1
set key box lt 1 lc -1 lw 2
set xlabel "log(t)"
set ylabel "N(t)"
set xrange [6:10]
set xtics 6,0.5,10
set grid ytics ls 2 lc rgb "black"
set title "Histograma de Cumulos Abiertos por Edades"
set style data histogram
set style histogram cluster gap 1
plot "Cumulos por Edades.tab" u 1:2 w boxes lc rgb 'blue' t 'Generacion Real',\
"Cumulos por Edades.tab" u 1:3 w boxes lc rgb 'red' t 'Generacion Constante'

我想要的是一个直方图,我可以看到两列,但我能得到的只是一个叠加在另一个上。

如果有人能帮我解决这个问题,我将不胜感激。

【问题讨论】:

    标签: gnuplot histogram


    【解决方案1】:

    使用set style data histogram 等同于使用with histogram。你用with boxes 覆盖它。

    最简单的方法是绘制为histogram。这是一个最小的运行脚本:

    set style data histogram
    set style histogram cluster gap 1
    plot "Cumulos por Edades.tab" u 2, "" u 3
    

    这显示了如何绘制直方图:第一行中的值以x=0 为中心,第二行以x=1 为中心,依此类推。不幸的是,您不能像在任何其他绘图样式中一样将第一列用作数字x-value。但是您可以使用 xtic(1) 来使用值“原样”,它将第一列的值作为字符串读取并将其用作 tic 标签:

    set style data histogram
    set style histogram cluster gap 1
    plot "Cumulos por Edades.tab" u 2:xtic(1), "" u 3
    

    第二个选项是使用boxes 绘图风格:

    plot "Cumulos por Edades.tab" u 1:2 with boxes, "" u 1:3 with boxes
    

    在这里,两列都围绕相同的x-value 绘制,尽管重叠。所以你需要将一列向左移动一点,另一列向右移动。而且你必须设置一个固定的boxwidth:

    set boxwidth 0.2 absolute
    plot "Cumulos por Edades.tab" u ($1-0.1):2 with boxes,\
         "" u ($1+0.1):3 with boxes
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-29
      • 1970-01-01
      • 2013-07-28
      • 1970-01-01
      • 2017-08-25
      • 2016-05-27
      相关资源
      最近更新 更多