How to use a Matplotlib proxy artist with stackplot?
Question: Example (runs in `ipython --pylab`):

    
    
    x = arange(25)
    Y = maximum(0,2+randn(7,25))
    stackplot(x,Y)
    legend(('A','B','C','D','E','F','G'))
    

**The problem:** instead of a proper legend, I get an empty rectangle. This is
a [known issue](https://github.com/matplotlib/matplotlib/issues/1943) and one
work-around is using another plot element that supports legend, also called a
_[proxy artist](http://matplotlib.org/users/legend_guide.html#using-proxy-
artist)_. Now I wonder how this idiom is translated to my case with seven data
series. Here is what I tried:

    
    
     proxy = [Rectangle((0,0), 0,0) for _ in Y]
     legend(proxy, ('A','B','C','D','E','F','G'))
    

Now I have a legend with 7 elements, but they are all blue. How can I have the
proxy artists match the stackplot colors?


Answer: You can read the color from the `PolyCollections` which form the stackplot.

    
    
    import numpy as np
    import matplotlib.pyplot as plt
    import matplotlib as mpl
    
    x = np.arange(25)
    Y = np.maximum(0,2+np.random.randn(7,25))
    
    fig, ax = plt.subplots()
    
    sp = ax.stackplot(x,Y)
    
    proxy = [mpl.patches.Rectangle((0,0), 0,0, facecolor=pol.get_facecolor()[0]) for pol in sp]
    
    ax.legend(proxy, ('A','B','C','D','E','F','G'))
    

![enter image description here](http://i.stack.imgur.com/FxD0B.png)

