bar legends


I have the following code to produce a greyscale stack bar graph for
an arbitrary numbers of input vectors with an arbitrary number of
elements. This is what I have so far. It works fine - the only problem
is I have n times too many legend entries where n is the number of
input vectors. I just want to label the color for the first element of
each vector once, but I'm a bit stuck on how to do this.

Any help appreciated.

def plot_stacked(*vals):
    numstacks = len(vals)
    vallength = set([len(val) for val in vals])
    if len(vallength) > 1:
        raise ValueError,'All input values should have the same length'
    vallength = vallength.pop()

    ind = 0.25 + arange(numstacks)
    width = 0.5
    bottom = zeros(numstacks)
    print arange(vallength)
    colorvals = arange(vallength) * (1.0/(vallength-1))
    print colorvals
    orderlabels = ['First Order','Second Order','Third Order','Fourth Order']
    labels = orderlabels[:vallength-1] + ['Higher Order']

    for i in range(vallength):
        ivals = [val[i] for val in vals]
        bar(ind, ivals, width, bottom=bottom,
        bottom += ivals