How to display a stacked barchart in Gnuplot?

user3383 picture user3383 · Feb 23, 2011 · Viewed 15.6k times · Source

I have a data file that looks a bit like this:

A 0.2  0.5
B 0.65 0.8
C 0.4  0.2

i.e., it contains three columns where the first column contains labels and the other two columns float values. Columns are separated by spaces.

I'd like to plot this in a way that the labels appear as tics on the x-axis while the columns are plotted as two differently colored barcharts on top of each other.

How can I achieve this using Gnuplot?

Answer

chl picture chl · Apr 25, 2011

Assuming your data are stored in the file 1.dat, stacked barcharts might be generated as follows:

set style data histograms
set style histogram rowstacked
set boxwidth 1 relative
set style fill solid 1.0 border -1
set yrange [0:1.5]
set datafile separator " "
plot '1.dat' using 2 t "Var 1", '' using 3:xticlabels(1) t "Var 2"

As you can see, barcharts are no different from histograms (at least, from within Gnuplot). More information can be found on gnuplot demo page.

enter image description here