@@ -41,26 +41,27 @@ def stackplot(axes, x, *args, **kwargs):
41
41
can be found at http://www.leebyron.com/else/streamgraph/.
42
42
43
43
44
+ *labels* : A list or tuple of labels to assign to each data series.
45
+
46
+
44
47
*colors* : A list or tuple of colors. These will be cycled through and
45
48
used to colour the stacked areas.
46
49
All other keyword arguments are passed to
47
50
:func:`~matplotlib.Axes.fill_between`
48
51
52
+
49
53
Returns *r* : A list of
50
54
:class:`~matplotlib.collections.PolyCollection`, one for each
51
55
element in the stacked area plot.
52
-
53
- Note that :class:`~matplotlib.legend.Legend` does not support
54
- :class:`~matplotlib.collections.PolyCollection` objects. To create a
55
- legend on a stackplot, use a proxy artist:
56
- http://matplotlib.org/users/legend_guide.html#using-proxy-artist
57
56
"""
58
57
59
58
if len (args ) == 1 :
60
59
y = np .atleast_2d (* args )
61
60
elif len (args ) > 1 :
62
61
y = np .row_stack (args )
63
62
63
+ labels = iter (kwargs .pop ('labels' , []))
64
+
64
65
colors = kwargs .pop ('colors' , None )
65
66
if colors is not None :
66
67
axes .set_color_cycle (colors )
@@ -104,12 +105,14 @@ def stackplot(axes, x, *args, **kwargs):
104
105
# Color between x = 0 and the first array.
105
106
r .append (axes .fill_between (x , first_line , stack [0 , :],
106
107
facecolor = six .next (axes ._get_lines .color_cycle ),
108
+ label = six .next (labels , None ),
107
109
** kwargs ))
108
110
109
111
# Color between array i-1 and array i
110
112
for i in xrange (len (y ) - 1 ):
111
113
color = six .next (axes ._get_lines .color_cycle )
112
114
r .append (axes .fill_between (x , stack [i , :], stack [i + 1 , :],
113
115
facecolor = color ,
116
+ label = six .next (labels , None ),
114
117
** kwargs ))
115
118
return r
0 commit comments