Using gnuplot for stacked histograms

I am trying to create a complex 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 tried to adapt the script from the 4th example, and currently 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 that I'm not sure about using 2:xtic(1) . I know this uses xtic values ​​as the first column I want. But I do not know what the using 2 part represents. This is a screenshot of what the script creates:

enter image description here

Everything is fine in the image, except for the red bar, which should not be. Can someone explain to me why he appears and how to get rid of him?

+6
source share
1 answer

using 2 means that gnuplot will use the second column from the file for the data it draws. If you draw x data versus y data, the plot data using 1:2 command if the x data is in column 1 and the y data is in column 2. plot using 2 will display the data from column 2 along the y axis and for each data point, x coordinate will be increased by 1.

You will notice that the green and red bars are the same size: they both use column 2. If you do not want the first (red) bar to be displayed, you can change the chart command to

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

With this command, the xtic shortcuts will remain unchanged, and the first bar will no longer be there. Note that the colors for the data will be changed using this command, since the first that is drawn will be red, the second will be green and the third will be blue.

+10
source

Source: https://habr.com/ru/post/917024/


All Articles