Sabine van der Linden | 26 Jan 14:20 2012
Picon

Using Proxy Artist to make legend

Hello, 

I have made a plot with a fill_between part, which does not show up in the
legend. I have read that I have to use a proxy artist for this, but I have no
clue where to place this, and how.. The fill between works fine, it's just the
legend that is not really cooperating ;) 

import matplotlib.pyplot as plt

plt.plot(dbx, gemlist)
plt.title('Reekslengte '+str(i))
plt.xlabel('signaal-ruisverhouding ingangssignaal (dB)')
plt.ylabel('signaal-ruisverhouding uitgangssignaal (dB)')
plt.xlim(-36, 22)

plt.fill_between(dbx, boven, onder, color='b', alpha=0.1)
plt.legend(loc=4)
plt.show()

Tnx in advance :) 

Sabine 

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
(Continue reading)

Tony Yu | 26 Jan 19:56 2012
Picon

Re: Using Proxy Artist to make legend



On Thu, Jan 26, 2012 at 8:20 AM, Sabine van der Linden <info-6F38vi1gkRaEVqv0pETR8A@public.gmane.org> wrote:
Hello,

I have made a plot with a fill_between part, which does not show up in the
legend. I have read that I have to use a proxy artist for this, but I have no
clue where to place this, and how.. The fill between works fine, it's just the
legend that is not really cooperating ;)

import matplotlib.pyplot as plt

plt.plot(dbx, gemlist)
plt.title('Reekslengte '+str(i))
plt.xlabel('signaal-ruisverhouding ingangssignaal (dB)')
plt.ylabel('signaal-ruisverhouding uitgangssignaal (dB)')
plt.xlim(-36, 22)

plt.fill_between(dbx, boven, onder, color='b', alpha=0.1)
plt.legend(loc=4)
plt.show()

Tnx in advance :)

Sabine


I have a convenience function (copied below) in my python path that I like to use for this purpose.

Hope that helps,
-Tony

#~~~~

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)
    ax.add_patch(p)
    return p


 
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@...
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Gmane