On Thu, Jun 21, 2012 at 4:09 PM, Andre' Walker-Loud <walksloud@gmail.com> wrote:
Hi All,

Sometimes, instead of using data points with error bars, I instead use fill_between to create a little bar, with a band which I use alpha=.3 or so.

I have tried unsuccessfully to find an easy way to create a legend label for this band - I am trying to have a similar band appear in my legend.

I am not attached to fill_between if there is a similar way to create such a "little bar" to represent my data point.



Hi Andre,

Unfortunately, I think the preferred method is to create a proxy artist:


Basically, you draw a fake patch with the same parameters as your fill (see example below).

Hope that helps,

# example from http://comments.gmane.org/gmane.comp.python.matplotlib.general/29476
def fill_between(x, y1, y2=0, ax=None, **kwargs):
    """Plot filled region between `y1` and `y2`.

    This function works exactly the same as matplotlib's fill_between, except
    that it also plots a proxy artist (specifically, a rectangle of 0 size)
    so that it can be added it appears on a legend.
    ax = ax if ax is not None else plt.gca()
    ax.fill_between(x, y1, y2, **kwargs)
    p = plt.Rectangle((0, 0), 0, 0, **kwargs)
    return p