'- *parent*: the artist that contains the legend
- *handles*: a list of artists (lines, patches) to be added to the
legend
- *labels*: a list of strings to label the legend
Optional keyword arguments:
Keyword            Description
loc                Location code string, or tuple (see below).
prop               the font property
fontsize           the font size (used only if prop is not specified)
markerscale        the relative size of legend markers vs. original
markerfirst        If True (default), marker is to left of the label.
numpoints          the number of points in the legend for line
scatterpoints      the number of points in the legend for scatter plot
scatteryoffsets    a list of yoffsets for scatter symbols in legend
frameon            If True, draw the legend on a patch (frame).
fancybox           If True, draw the frame with a round fancybox.
shadow             If True, draw a shadow behind legend.
framealpha         Transparency of the frame.
edgecolor          Frame edgecolor.
facecolor          Frame facecolor.
ncol               number of columns
borderpad          the fractional whitespace inside the legend border
labelspacing       the vertical space between the legend entries
handlelength       the length of the legend handles
handleheight       the height of the legend handles
handletextpad      the pad between the legend handle and text
borderaxespad      the pad between the axes and legend border
columnspacing      the spacing between columns
title              the legend title
bbox_to_anchor     the bbox that the legend will be anchored.
bbox_transform     the transform for the bbox. transAxes if None.
The pad and spacing parameters are measured in font-size units.  e.g.,
a fontsize of 10 points and a handlelength=5 implies a handlelength of
50 points.  Values from rcParams will be used if None.
Users can specify any arbitrary location for the legend using the
*bbox_to_anchor* keyword argument. bbox_to_anchor can be an instance
of BboxBase(or its derivatives) or a tuple of 2 or 4 floats.
See :meth:`set_bbox_to_anchor` for more detail.
The legend location can be specified by setting *loc* with a tuple of
2 floats, which is interpreted as the lower-left corner of the legend
in the normalized axes coordinate.'

def __init__(self, parent, handles, labels, loc=None, numpoints=None, markerscale=None, markerfirst=True, scatterpoints=None, scatteryoffsets=None, prop=None, fontsize=None, borderpad=None, labelspacing=None, handlelength=None, handleheight=None, handletextpad=None, borderaxespad=None, columnspacing=None, ncol=1, mode=None, fancybox=None, shadow=None, title=None, framealpha=None, edgecolor=None, facecolor=None, bbox_to_anchor=None, bbox_transform=None, frameon=None, handler_map=None):

    from matplotlib.axes import Axes
    from matplotlib.figure import Figure
    Artist.__init__(self)
    if (prop is None):
        if (fontsize is not None):
            self.prop = FontProperties(size=fontsize)
        else:
            self.prop = FontProperties(size=rcParams[u'legend.fontsize'])
    elif isinstance(prop, dict):
        self.prop = FontProperties(**prop)
        if (u'size' not in prop):
            self.prop.set_size(rcParams[u'legend.fontsize'])
    else:
        self.prop = prop
    self._fontsize = self.prop.get_size_in_points()
    self.texts = []
    self.legendHandles = []
    self._legend_title_box = None
    self._custom_handler_map = handler_map
    locals_view = locals()
    for name in [u'numpoints', u'markerscale', u'shadow', u'columnspacing', u'scatterpoints', u'handleheight', u'borderpad', u'labelspacing', u'handlelength', u'handletextpad', u'borderaxespad']:
        if (locals_view[name] is None):
            value = rcParams[(u'legend.' + name)]
        else:
            value = locals_view[name]
        setattr(self, name, value)
    del locals_view
    handles = list(handles)
    if (len(handles) < 2):
        ncol = 1
    self._ncol = ncol
    if (self.numpoints <= 0):
        raise ValueError((u'numpoints    must    be    >    0;    it    was    %d' % numpoints))
    if (scatteryoffsets is None):
        self._scatteryoffsets = np.array([(3.0 / 8.0), (4.0 / 8.0), (2.5 / 8.0)])
    else:
        self._scatteryoffsets = np.asarray(scatteryoffsets)
    reps = (int((self.scatterpoints / len(self._scatteryoffsets))) + 1)
    self._scatteryoffsets = np.tile(self._scatteryoffsets, reps)[:self.scatterpoints]
    self._legend_box = None
    if isinstance(parent, Axes):
        self.isaxes = True
        self.axes = parent
        self.set_figure(parent.figure)
    elif isinstance(parent, Figure):
        self.isaxes = False
        self.set_figure(parent)
    else:
        raise TypeError(u'Legend    needs    either    Axes    or    Figure    as    parent')
    self.parent = parent
    if (loc is None):
        loc = rcParams[u'legend.loc']
        if ((not self.isaxes) and (loc in [0, u'best'])):
            loc = u'upper    right'
    if isinstance(loc, six.string_types):
        if (loc not in self.codes):
            if self.isaxes:
                warnings.warn((u'Unrecognized    location    "%s".    Falling    back    on    "best";    valid    locations    are\n DCTB %s\n' % (loc, u'\n DCTB '.join(self.codes))))
                loc = 0
            else:
                warnings.warn((u'Unrecognized    location    "%s".    Falling    back    on    "upper    right";    valid    locations    are\n DCTB %s\n' % (loc, u'\n DCTB '.join(self.codes))))
                loc = 1
        else:
            loc = self.codes[loc]
    if ((not self.isaxes) and (loc == 0)):
        warnings.warn(u'Automatic    legend    placement    (loc="best")    not    implemented    for    figure    legend.    Falling    back    on    "upper    right".')
        loc = 1
    self._mode = mode
    self.set_bbox_to_anchor(bbox_to_anchor, bbox_transform)
    if (facecolor is None):
        facecolor = rcParams[u'legend.facecolor']
    if (facecolor == u'inherit'):
        facecolor = rcParams[u'axes.facecolor']
    if (edgecolor is None):
        edgecolor = rcParams[u'legend.edgecolor']
    if (edgecolor == u'inherit'):
        edgecolor = rcParams[u'axes.edgecolor']
    self.legendPatch = FancyBboxPatch(xy=(0.0, 0.0), width=1.0, height=1.0, facecolor=facecolor, edgecolor=edgecolor, mutation_scale=self._fontsize, snap=True)
    if (fancybox is None):
        fancybox = rcParams[u'legend.fancybox']
    if fancybox:
        self.legendPatch.set_boxstyle(u'round', pad=0, rounding_size=0.2)
    else:
        self.legendPatch.set_boxstyle(u'square', pad=0)
    self._set_artist_props(self.legendPatch)
    self._drawFrame = frameon
    if (frameon is None):
        self._drawFrame = rcParams[u'legend.frameon']
    self._init_legend_box(handles, labels, markerfirst)
    if (framealpha is None):
        self.get_frame().set_alpha(rcParams[u'legend.framealpha'])
    else:
        self.get_frame().set_alpha(framealpha)
    self._loc = loc
    self.set_title(title)
    self._last_fontsize_points = self._fontsize
    self._draggable = None
