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
···
On Thu, Jan 26, 2012 at 8:20 AM, Sabine van der Linden <info@…3936…> 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
#~~~~
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