Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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'

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:

enter image description here

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?

like image 248
Mike Kwan Avatar asked May 30 '12 15:05

Mike Kwan


1 Answers

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.

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'

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.

like image 166
andyras Avatar answered Oct 07 '22 10:10

andyras