Stacked bar charts

First of all, thanks for matplotlib.

This is far and away the best python plotting package I have come across.

I’ve attached a patch for axes.py that allows ‘stacked bar charts’ to be produced using the bar function.

The idea with a stacked bar chart is that you have several series of data that naturally stack up on top of each other. You can achieve this effect with a small fix to the bar function. All you have to do is to specify the offsets along the y-axis for each value being plotted (by default these offsets would be all zero, equivalent to the existing function).

See stacked_bar.py for an example of how you might use this.

The patch adds an extra keyword arguement , yoff, to plot.

This allows you to supply a list of offsets for the values to be plotted.

Using this you can ‘stack’ up results by using successive calls to bar, so long as you are careful to get the offsets right.

John

stacked.patch (917 Bytes)

stacked_bar.py (759 Bytes)