legend with

I am trying to plot a line area graph similar to a stacked bar chart.

E.g
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111)

ind = np.arange(3)
y1 = np.array([1,2,3])
y2 = y1 * 2
a = ax.fill_between(ind, y1, np.zeros(len(ind)), facecolor=‘r’)
b = ax.fill_between(ind, y2, y1, facecolor=‘b’)
plt.show()

However, when I try to make my legend,

ax.legend((a,b),(‘a’,‘b’))

I get an AttributeError. How do I extract the information I need from the PolyCollection object to make a legend?

Thanks,

  • Chuck