2
votes

I have a data file like this:

"Execution"  500
"Overhead 1" 200
"Overhead 2" 75

I am trying to plot a histogram of this data that shows the Execution time as a single bar graph but Overhead 1 and Overhead 2 as a single stacked bar graph.

This is what I have so far:

set terminal postscript eps 24
set output "wq_time_profile.eps"
set size 0.95,0.95
set boxwidth 1.0 relative    
set style fill solid 0.5 noborder   
set style data histogram 
set style histogram cluster gap 1  
set ylabel "Time (mins)"                                                                      
plot "wq_time_profile.dat" u 1 notitle, "" u 2 notitle, "" u 3 notitle

I can't quite get my head around how to show rows 2 and 3 as a stacked bar graph while showing row 1 as standalone bar graph in the same plot. Is this possible in gnuplot? I am using gnuplot v4.2. Thanks!

EDIT: Modified the title and question to clarify that the plot needs to contain a single standalone bar graph and a stacked bar graph in the same gat the same plot

1

1 Answers

2
votes

This seems to work:

set style fill solid 0.5 noborder
set style histogram columnstacked
set style data histogram
set ylabel "Time (mins)"
plot "test.dat" u 2 notitle with histogram

If you want to have a key with the colors-labels in it:

set style histogram columnstacked
set style data histogram
set style fill solid 0.5 noborder
set ylabel "Time (mins)"
plot "test.dat" u 2:key(1) with histogram

After reading your edit and playing around a bit, this is still possible, but I needed to modify your datafile. (I hope that's Ok):

"Execution"  500


"foo" NaN
"Overhead 1" 200
"Overhead 2" 75

Now the plotting script:

set style histogram columnstacked
set style data histogram
set style fill solid 0.5 noborder
set ylabel "Time (mins)"
plot for [i=0:1] "test.dat" index i u ($2):key(1) with histogram

There are a bunch of subtleties here. The pair of blank records is a way to create a separate "index" for gnuplot to use when plotting. The first bar is by itself in a dataset. Here's the problem, Gnuplot will match the first record from index 0 with the first record from index 1 and plot them with the same color. That's ugly. So we need to insert a fake record in the index=1 dataset which won't make any plot, but will take up a color. That's what the "foo" NaN line is designed to do. I also needed to modify the plot line to plot both of the indexes. And the using specification needs to change from 2:key(1) to ($2):key(1) as there is a slight difference in how the two forms handle missing data.