0

I'm trying to use gnuplot to plot a stacked histogram of some data but it skips the first bin (the first row of the data file).

The data is:

1 0.2512 0.0103 0.9679
2 0.4730 0.2432 0.8468
3 0.6669 0.2826 0.6895
4 0.6304 0.2268 0.7424

And the plot code is

set title "Data"
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 'data.dat' using 2:xtic(1) title 'X', '' using 3 title 'Y', '' using 4 title 'Z'

The output isenter image description here. I checked it and it correctly displays the data of the 2nd, 3rd and 4th rows of the data file. Why am I missing the first bin..?

Thanks a lot!

I already checked this with no help: Using gnuplot for stacked histograms

Community
  • 1
  • 1
powder
  • 1,163
  • 2
  • 16
  • 32
  • why `set key autotitle columnheader`? – Azad Nov 06 '15 at 06:45
  • Probably ended up there from an old cut and paste, doesn't do much you're right.. Removing it and the title in the plot line showed that gnuplot was taking the first line as the title of the columns, so adding a dummy line with the titles as first line solved the problem – powder Nov 06 '15 at 06:50
  • 1
    [gnuplot: first row of data skipped](http://stackoverflow.com/q/28346228/2604213) – Christoph Nov 06 '15 at 07:16
  • I really don't know why this question have been downvoted. I find this really useful! – Alfonso Santiago Sep 26 '19 at 09:30

1 Answers1

1

As it turns out, it was a very simple mistake, that I've fixed mostly thanks to Azad comment about the titles.

The new code is:

set title "Position error along the three axis"
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 'data.dat' using 2:xtic(1), '' using 3, '' using 4 

Titles have been removed from the code. Gnuplot was taking the first row (which should have been the first bin) as the titles and then it was overwritten by the title 'X' etc.

The new data looks like this:

0 X Y Z
1 0.2512 0.0103 0.9679
2 0.4730 0.2432 0.8468
3 0.6669 0.2826 0.6895
4 0.6304 0.2268 0.7424

This fixed the problem, now all the bins are correctly displayed!

powder
  • 1,163
  • 2
  • 16
  • 32