3
votes

I would like to reproduce a bar chart like this one, i.e.: multiple groups, every group has many bars (4 bars in my case), each bar is segmented in a few slices (two slices in my case).

In my case, I have four algorithms applied on vectors of different sizes (2^0 to 2^20). Each algorithm has two "sections", local computation and communication. For each vector size I want to show the time required by each algorithm to perform the local computation and the communication, along with the total time corresponding to the sum of these two sections.

As a result, I would like to have a group for every vector size. In each group there are four bars corresponding to the four algorithms and each bar is segmented in a (e.g.) red part corresponding to the local computation and a blue part corresponding to the communication.

Is this feasible with gnuplot? I can provide data in whatever format is useful.

Many thanks in advance.

1
Sample data and a sample script would highly help you in getting answer. :) Also indicate what is missing in your script and what you tried. - Bernhard
Of course. I placed a sample of my data here: pastebin.com/vtemLn98. Since I'm an absolute beginner (I'm moving from Matlab to gnuplot), I don't even know whether what I want to do is feasible (in Matlab, e.g., it's impossible unless you go low-level or apply some unusual tricks), so I did not start a script yet. - Spiros

1 Answers

0
votes

For your data set it doesn't make sense to stack the local and comm parts, because the comm part is to small to see it in the graph. In any case it would also be quite tricky to combine stacked and clustered, depending on the further requirements (legend entries, tick labels etc).

Here is an example of how to plot a clustered histogram for your data set:

set style histogram clustered gap 1
set style data histogram
set style fill solid 1.0 noborder

set termoption enhanced

set xtics out nomirror

myxtic(x) = sprintf('2^{%d}', int(floor(log(x)/log(2) + 0.5)))
plot 'test.dat' using ($2+$3):xtic(myxtic(stringcolumn(1))) title 'Algorithm 1',\
     for [i=2:4] '' using (column(2*i)+column(2*i+1)) title sprintf('Algorithm %d', i)

The result is:

enter image description here

To group by algorithm, you can create new groups with the newhistogram keyword:

set style histogram rowstacked title offset 4,1
set boxwidth 0.9 relative
set style fill solid 1.0 border lt -1
set xtics rotate by 90 right
plot newhistogram "Algorithm 1" lt 1,\
     'test.dat' using 2:xtic(1) title columnheader, \
     '' using 3 title columnheader,\
     newhistogram "Algorithm 2" lt 1,\
     'test.dat' using 4:xtic(1) notitle, \
     '' using 5 notitle,\
     newhistogram "Algorithm 3" lt 1,\
     'test.dat' using 6:xtic(1) notitle, \
     '' using 7 notitle,\
     newhistogram "Algorithm 4" lt 1,\
     'test.dat' using 8:xtic(1) notitle, \
     '' using 9 notitle

The local and comm dat are stacked, but the comm part is so small, that you cannot see it in the graph (only when you zoom in).

For the output I used 4.6.3 and the following settings:

set terminal pngcairo size 1000,400
set output 'test.png'
set xtics font ',6'

The result is:

enter image description here

A bit more sophisticated display of the xtics requires some tricking, because for histograms the xtics aren't treated as being numerical, but rather strings. Here is an example:

set terminal pngcairo size 1000,400
set output 'test.png'

set style histogram rowstacked title offset 0,-0.5
set bmargin 3
set boxwidth 0.9 relative
set style fill solid 1.0 border lt -1
set termoption enhanced
set xtics out nomirror
myxtic(x) = (int(floor(log(x)/log(2) + 0.5)) % 5 == 0) ? sprintf('2^{%d}', int(floor(log(x)/log(2) + 0.5))) : ""

plot newhistogram "Algorithm 1" lt 1,\
     'test.dat' using 2:xtic(myxtic(real(stringcolumn(1)))) title columnheader, \
     '' using 3 title columnheader,\
     newhistogram "Algorithm 2" lt 1,\
     'test.dat' using 4:xtic(myxtic(real(stringcolumn(1)))) notitle, \
     '' using 5 notitle,\
     newhistogram "Algorithm 3" lt 1,\
     'test.dat' using 6:xtic(myxtic(real(stringcolumn(1)))) notitle, \
     '' using 7 notitle,\
     newhistogram "Algorithm 4" lt 1,\
     'test.dat' using 8:xtic(myxtic(real(stringcolumn(1)))) notitle, \
     '' using 9 notitle

With the result

enter image description here