tcurdt
tcurdt

Reputation: 15778

stacked graph with gnuplot

My data file looks like this

A 20120301 4
A 20120302 3
B 20120301 5
B 20120302 6
C 20120303 5

except there are many more than just A,B,C and I want to create a stacked graph with gnuplot (similar to the "Stacked histograms" from the gnuplot demos)

20120301 = (A:4 + B:5)
20120302 = (A:3 + B:6)
20120303 = (C:5)

So far I could not convince plot to read the data in that format. Do I have re-arrange the data file for this? Or is there a way for gnuplot to read the data in that format?

Upvotes: 1

Views: 1333

Answers (1)

mgilson
mgilson

Reputation: 309821

I think I've managed to beat it into a form that will work (you'll need at least gnuplot 4.3):

set boxwidth 0.75 absolute
set style fill   solid 1.00 border lt -1
set datafile missing '-'
set style histogram rowstacked
set style data histograms
set yrange [0:]
plot for [i=2:4] 'test.dat' u i,'' u (0.0):xtic(1) notitle

and here's the datafile test.dat

#date     A B C
#missing data is marked by a minus sign
20120301  4 5 -   
20120302  3 6 -
20120303  - - 5

Phew! I've never been much good with gnuplot when it comes to histograms. Hopefully this will work for you (Sorry about the change to your datafile).

Upvotes: 1

Related Questions