1
votes

I'd like to start by saying I am very new to gnuplot. I am attempting to plot multiple stacked histograms that have been normalized so that the height of each bar is 1. I'd also prefer to no have to amend my data files to include the total as the last entry as I have a lot of data files to plot and this would take a lot of time. I've looked around and I know this can be done, but I have been unsuccessful in adapting examples I've found to work with the code I am using. The data file I am using (shortened considerably) is named "Test.dat" and formatted as follows:

#a = 2  
#b 1  2  3  X  
b=1  1  3  1   
b=2  0  1  1

#a = 4  
b 1  2  3  X   
b=1  1  1.5  1.5     
b=2  1  2.1  1.9

Here each row beginning with b=x is meant to be a single bar, and there are two groups of two bars corresponding to an a=x. My .gp file currently looks like this:

set style data histogram
set style histogram rowstacked gap .5 title offset 0, -1
set style fill solid border -1
set boxwidth .75 relative
set yrange [0:]
unset xtics

plot \\

newhistogram  "b=2"  lt 1, for[col=2:4] 'Test.dat' index 0 u col:xtic(1)   notitle \
,newhistogram "b=4"  lt 1, for[col=2:4] 'Test.dat' index 1 u col:xtic(1)   notitle \

This give the image, but this is what I would like to get. I'd appreciate any assistance you could provide.

1

1 Answers

0
votes
  1. You have missed a comment sign "#" in the second data bolck.

  2. You have to separate each data block with 2 blank lines.

  3. You are using "b=1" and "b=2" in the data file, but "b=2" and b=4 in the script.

  4. Last: gnuplot is able to make stacked histograms, but there is no way to normalize them automatic, but manually :-/

    set style data histogram
    set style histogram rowstacked gap .5 title offset 0, -1
    set style fill solid border -1
    set boxwidth .75 relative
    set yrange [0:]
    unset xtics
    
    plot \\\
    
    newhistogram  "b=1"  lt 1, for[col=2:4] 'Test.dat' index 0 u (column(col)/$5):xtic(1)   notitle, \
    newhistogram "b=2"  lt 1, for[col=2:4] 'Test.dat' index 1 u (column(col)/$5):xtic(1)   notitle