 # Getting crazy with "legend"

Hi, I found an odd problem with "legend". I get the right

> labels/text but not the "small colour bars" associated to
> them. There is something I must do wrong..

> Here is a fake example:

> Thanks for any input on this!

There are two problems with your example

pa1 = hist(arange(1,100,1), bins=arange(0,100,10))
pa2 = hist(arange(1,100,1), bins=arange(0,100,10))
clf()

matplotlib provides a "no plot" hist function in matplotlib.mlab. So
rather than calling the pylab hist (which plots) and then clearing the
figure with clf (you forgot the parentheses of clf, btw), call
matplotlib.mlab.hist which computes the histogram but doesn't plot.

width = 5 # the width of the bars
p1 = bar(pa1, pa1, width, color='r')
p2 = bar(pa2+width, pa2, width, color='y')

The above code is OK.

This is the second problem. pa1 and pa2 in your example are the
return values from pylab hist, which is (n, bins, patches). You need
to pass the patches returned by the bar command, eg p1, p2

Here is the recommended way:

from pylab import *
import matplotlib.mlab # provides hist w/o plot

n1, bins1 = matplotlib.mlab.hist(arange(1,100,1), bins=arange(0,100,10))
n2, bins1 = matplotlib.mlab.hist(arange(1,100,1), bins=arange(0,100,10))

width = 5 # the width of the bars
p1 = bar(bins1, n1, width, color='r')
p2 = bar(bins1+width, n2, width, color='y')