1
votes

I want to plot multiple rowstacked histograms on the same graph using gnuplot. A sample data file is the following:

App1 20 30 50
App2 10 20 70

The script I use is this

set terminal jpeg medium
set output "histo.jpeg"
set boxwidth 0.75 absolute
set style fill solid 1.00 border -1
set style data histogram
set style histogram rowstacked
set xtics 1000 nomirror
set ytics 100 nomirror
set mxtics 2
set mytics 2
set ytics 10
set yrange [0:120]
set ylabel "Total time"
set key below vertical

plot 'data' using 2 t "Idle", '' using 3 t "User space", '' using 4 :xtic(1) t "Kernel space"

The result I am getting is this:enter image description here

I would like to have separate keys below each histogram, since I want to display the amount of time each element is occupying which is different from one graph to the other. Also, possibly some elements appearing on one histogram will not appear on the other.

My intention is to create a script that generates both the data file and the gnuplot script to automate this process.

I have achieved the above using jgraph but the results are pretty poor in terms of appearance.

Thanks a lot,

Spap

1

1 Answers

2
votes

Unfortunately, there is no clean way to do this. You can achieve something similar by plotting your data the first time around (in a multiplot) and then making "null" plots to add more keys after the fact.

set boxwidth 0.75 absolute 
set style fill solid 1.00 border -1
set style data histogram
set style histogram rowstacked
set xtics 1000 nomirror
set ytics 100 nomirror
set mxtics 2
set mytics 2
set ytics 10
set yrange [0:120]
set ylabel "Total time"
set multiplot

#These might be helpful to keep all the "plots" aligned.
set lmargin at screen .2
set rmargin at screen .9
set tmargin at screen .9
set bmargin at screen .2

set key at first .5,screen .1 #could be "set key at screen 0.1,0.1"  You'll have to play around with it.

plot 'data' using 2 t "Idle", \
     '' using 3 t "User space", \
     '' using 4 :xtic(1) t "Kernel space"

unset xtics
unset xlabel
unset ytics
unset ylabel
unset title
unset border 
set xrange [GPVAL_X_MIN:GPVAL_X_MAX]

set key at first 1.5,screen .1 
plot NaN t "Idle (app2)" w boxes, \
     NaN t "User space (app2)" w boxes, \
     NaN t "Kernel space (app2)" w boxes

unset multiplot