【问题标题】:Using gnuplot for stacked histograms将 gnuplot 用于堆叠直方图
【发布时间】:2012-06-04 21:33:42
【问题描述】:

我正在尝试使用以下数据创建堆叠直方图:

8.01    1   5   1   
8.02    3   5   1
8.03    4   4   1
8.04    3   4   1
8.05    1   2   1

我已尝试从第 4 个示例中调整脚本,目前我正在使用:

set title "Test"
set key invert reverse Left outside
set key autotitle columnheader
set style data histogram
set style histogram rowstacked
set style fill solid border -1
set boxwidth 0.75

plot 'test.dat' using 2:xtic(1),  '' using 2 title 'Col1', '' using 3 title 'Col2', '' using 4 title 'Col3'

我复制的部分我不确定是using 2:xtic(1)。我知道这使它使用xtic 值作为第一列,这就是我想要的。但我不知道using 2 部分代表什么。这是脚本生成的屏幕截图:

图像上的一切都很好,除了不应该存在的红条。有人可以向我解释它为什么会出现以及如何摆脱它吗?

【问题讨论】:

    标签: gnuplot histogram


    【解决方案1】:

    using 2 表示 gnuplot 将使用文件中的第二列作为它正在绘制的数据。如果您要绘制 x 数据与 y 数据,如果 x 数据在第 1 列而 y 数据在第 2 列,则命令为 plot data using 1:2plot using 2 将在 y 轴上绘制第 2 列的数据,并且对于每个数据点的x坐标将增加1。

    您会注意到绿色和红色条的大小相同:它们都使用第 2 列。如果您不希望出现第一个(红色)条,您可以将绘图命令更改为

    plot 'test.dat' using 2:xtic(1) title 'Col1', '' using 3 title 'Col2', '' using 4 title 'Col3'
    

    使用此命令,xtic 标签将保持不变,第一个条将不再存在。请注意,数据的颜色将随此命令而改变,因为绘制的第一件事是红色,第二个是绿色,第三个是蓝色。

    【讨论】: