使用gnuplot堆叠直方图 [英] Using gnuplot for stacked histograms
问题描述
我正在尝试使用以下数据创建堆叠的直方图:
I am trying to create a stacked histogram with the following data:
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个示例中的脚本,此刻我正在使用它:
I have tried to adapt the script from the 4th example and at the moment I'm using this:
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
部分代表什么.这是脚本产生的屏幕截图:
The part I copied which I'm not sure about is using 2:xtic(1)
. I know this makes it use the xtic
values as the first column, which is what I want. But I don't know what the using 2
part represents. This is a screenshot of what the script produces:
除了红色条(应该不存在)之外,其他所有内容都很好.有人可以向我解释为什么会出现这种现象以及如何消除它吗?
Everything is fine on the image except the red bar which should not be there. Could someone explain to me why it is appearing and how to get rid of it?
推荐答案
using 2
意味着gnuplot将使用文件中的第二列作为其正在绘制的数据.如果要绘制x数据与y数据,则如果x数据在第1列中,而y数据在第2列中,则命令为plot data using 1:2
.plot using 2
将在y轴上绘制第2列的数据,并分别数据点的x坐标将增加1.
using 2
means that gnuplot will use the 2nd column from the file for the data it is plotting. If you are plotting x data vs. y data, the command is plot data using 1:2
if x data is in column 1 and y data is in column 2. plot using 2
will plot the data from column 2 on the y axis, and for each data point the x coordinate will be incremented by 1.
您会注意到绿色和红色条的大小相同:它们都使用第2列.如果您不希望出现第一(红色)条,则可以将plot命令更改为
You'll notice that the green and red bars are the same size: they both use column 2. If you don't want the first (red) bar to appear, you could change the plot command to
plot 'test.dat' using 2:xtic(1) title 'Col1', '' using 3 title 'Col2', '' using 4 title 'Col3'
使用此命令,xtic标签将保持不变,并且第一个小节将不再存在.请注意,此命令将更改数据的颜色,因为首先绘制的颜色将是红色,第二个绿色和第三个蓝色.
With this command, the xtic labels will stay the same, and the first bar will no longer be there. Note that the colors for the data will change with this command, since the first thing plotted will be red, the second green and the third blue.
这篇关于使用gnuplot堆叠直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!