
 m[c           @` s  d  Z  d d l m Z m Z m Z m Z d d l Z d d l Z d d l Z d d l	 Z
 d d l m Z d d l m Z d d l m Z m Z d d l m Z m Z d d l j Z d d l m Z d d	 l m Z d d
 l m Z m Z m Z m Z d d l m  Z  m! Z! m" Z" m# Z# m$ Z$ d d l% m& Z& m' Z' m( Z( d d l% m) Z) m* Z* d d l+ m, Z, m- Z- m. Z. m/ Z/ d d l+ m0 Z0 d d l1 m2 Z2 m3 Z3 m4 Z4 d d l5 m6 Z6 d e0 f d     YZ7 d Z8 e j9 j: d e8  d e f d     YZ; e< d  Z= e< d  Z> d   Z? d S(   uO  
The legend module defines the Legend class, which is responsible for
drawing legends associated with axes and/or figures.

.. important::

    It is unlikely that you would ever create a Legend instance
    manually.  Most users would normally create a legend via the
    :meth:`~matplotlib.axes.Axes.legend` function. For more details on legends
    there is also a :doc:`legend guide </tutorials/intermediate/legend_guide>`.

The Legend class can be considered as a container of legend handles and
legend texts. Creation of corresponding legend handles from the plot elements
in the axes or figures (e.g., lines, patches, etc.) are specified by the
handler map, which defines the mapping between the plot elements and the
legend handlers to be used (the default legend handlers are defined in the
:mod:`~matplotlib.legend_handler` module).  Note that not all kinds of
artist are supported by the legend yet by default but it is possible to
extend the legend handler's capabilities to support arbitrary objects. See
the :doc:`legend guide </tutorials/intermediate/legend_guide>` for more
information.
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   rcParams(   t	   docstring(   t   Artistt   allow_rasterization(   t   silent_listt   is_hashable(   t   FontProperties(   t   Line2D(   t   Patcht	   Rectanglet   Shadowt   FancyBboxPatch(   t   LineCollectiont   RegularPolyCollectiont   CircleCollectiont   PathCollectiont   PolyCollection(   t   Bboxt   BboxBaset   TransformedBbox(   t   BboxTransformTot   BboxTransformFrom(   t   HPackert   VPackert   TextAreat   DrawingArea(   t   DraggableOffsetBox(   t   ErrorbarContainert   BarContainert   StemContaineri   (   t   legend_handlert   DraggableLegendc           B` s;   e  Z e d  d  Z d   Z d   Z d   Z d   Z RS(   u   locc         C` sQ   | |  _  | d k r! | |  _ n t d |   t j |  | | j d | d S(   u   
        Parameters
        ----------
        update : string
            If "loc", update *loc* parameter of legend upon finalizing.
            If "bbox", update *bbox_to_anchor* parameter.
        u   locu   bboxu'   update parameter '%s' is not supported.t   use_blitN(   u   locu   bbox(   t   legendt   _updatet
   ValueErrorR   t   __init__t   _legend_box(   t   selfR%   R$   t   update(    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyR(   7   s    	
c         C` s   |  j  j |  S(   N(   R%   t   contains(   R*   R%   t   evt(    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyt   artist_pickerJ   s    c         C` sa   |  j    } |  j d k r+ |  j |  n2 |  j d k rJ |  j |  n t d |  j   d  S(   Nu   locu   bboxu'   update parameter '%s' is not supported.(   t   get_loc_in_canvasR&   t   _update_loct   _update_bbox_to_anchort   RuntimeErrorR+   (   R*   t   loc_in_canvas(    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyt   finalize_offsetM   s    c         C` sz   |  j  j   } | j d k s- | j d k rO |  j  j d   |  j  j   } n  t |  } t | j |   |  j  _	 d  S(   Ni    (
   R%   t   get_bbox_to_anchort   widtht   heightt   set_bbox_to_anchort   NoneR   t   tuplet   transform_pointt   _loc(   R*   R3   t   bboxt   _bbox_transform(    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyR0   X   s    c         C` s2   |  j  j j } | j |  } |  j  j |  d  S(   N(   R%   t   axest	   transAxesR;   R8   (   R*   R3   t   trt   loc_in_bbox(    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyR1   f   s    (   t   __name__t
   __module__t   FalseR(   R.   R4   R0   R1   (    (    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyR#   6   s
   			u  
loc : int or string or pair of floats, default: :rc:`legend.loc` ('best' for axes, 'upper right' for figures)
    The location of the legend. Possible codes are:

        ===============   =============
        Location String   Location Code
        ===============   =============
        'best'            0
        'upper right'     1
        'upper left'      2
        'lower left'      3
        'lower right'     4
        'right'           5
        'center left'     6
        'center right'    7
        'lower center'    8
        'upper center'    9
        'center'          10
        ===============   =============


    Alternatively can be a 2-tuple giving ``x, y`` of the lower-left
    corner of the legend in axes coordinates (in which case
    ``bbox_to_anchor`` will be ignored).

bbox_to_anchor : `.BboxBase` or pair of floats
    Specify any arbitrary location for the legend in `bbox_transform`
    coordinates (default Axes coordinates).

    For example, to put the legend's upper right hand corner in the
    center of the axes the following keywords can be used::

        loc='upper right', bbox_to_anchor=(0.5, 0.5)

ncol : integer
    The number of columns that the legend has. Default is 1.

prop : None or :class:`matplotlib.font_manager.FontProperties` or dict
    The font properties of the legend. If None (default), the current
    :data:`matplotlib.rcParams` will be used.

fontsize : int or float or {'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'}
    Controls the font size of the legend. If the value is numeric the
    size will be the absolute font size in points. String values are
    relative to the current default font size. This argument is only
    used if `prop` is not specified.

numpoints : None or int
    The number of marker points in the legend when creating a legend
    entry for a `.Line2D` (line).
    Default is ``None``, which will take the value from
    :rc:`legend.numpoints`.

scatterpoints : None or int
    The number of marker points in the legend when creating
    a legend entry for a `.PathCollection` (scatter plot).
    Default is ``None``, which will take the value from
    :rc:`legend.scatterpoints`.

scatteryoffsets : iterable of floats
    The vertical offset (relative to the font size) for the markers
    created for a scatter plot legend entry. 0.0 is at the base the
    legend text, and 1.0 is at the top. To draw all markers at the
    same height, set to ``[0.5]``. Default is ``[0.375, 0.5, 0.3125]``.

markerscale : None or int or float
    The relative size of legend markers compared with the originally
    drawn ones.
    Default is ``None``, which will take the value from
    :rc:`legend.markerscale`.

markerfirst : bool
    If *True*, legend marker is placed to the left of the legend label.
    If *False*, legend marker is placed to the right of the legend
    label.
    Default is *True*.

frameon : None or bool
    Control whether the legend should be drawn on a patch
    (frame).
    Default is ``None``, which will take the value from
    :rc:`legend.frameon`.

fancybox : None or bool
    Control whether round edges should be enabled around the
    :class:`~matplotlib.patches.FancyBboxPatch` which makes up the
    legend's background.
    Default is ``None``, which will take the value from
    :rc:`legend.fancybox`.

shadow : None or bool
    Control whether to draw a shadow behind the legend.
    Default is ``None``, which will take the value from
    :rc:`legend.shadow`.

framealpha : None or float
    Control the alpha transparency of the legend's background.
    Default is ``None``, which will take the value from
    :rc:`legend.framealpha`.  If shadow is activated and
    *framealpha* is ``None``, the default value is ignored.

facecolor : None or "inherit" or a color spec
    Control the legend's background color.
    Default is ``None``, which will take the value from
    :rc:`legend.facecolor`.  If ``"inherit"``, it will take
    :rc:`axes.facecolor`.

edgecolor : None or "inherit" or a color spec
    Control the legend's background patch edge color.
    Default is ``None``, which will take the value from
    :rc:`legend.edgecolor` If ``"inherit"``, it will take
    :rc:`axes.edgecolor`.

mode : {"expand", None}
    If `mode` is set to ``"expand"`` the legend will be horizontally
    expanded to fill the axes area (or `bbox_to_anchor` if defines
    the legend's size).

bbox_transform : None or :class:`matplotlib.transforms.Transform`
    The transform for the bounding box (`bbox_to_anchor`). For a value
    of ``None`` (default) the Axes'
    :data:`~matplotlib.axes.Axes.transAxes` transform will be used.

title : str or None
    The legend's title. Default is no title (``None``).

borderpad : float or None
    The fractional whitespace inside the legend border.
    Measured in font-size units.
    Default is ``None``, which will take the value from
    :rc:`legend.borderpad`.

labelspacing : float or None
    The vertical space between the legend entries.
    Measured in font-size units.
    Default is ``None``, which will take the value from
    :rc:`legend.labelspacing`.

handlelength : float or None
    The length of the legend handles.
    Measured in font-size units.
    Default is ``None``, which will take the value from
    :rc:`legend.handlelength`.

handletextpad : float or None
    The pad between the legend handle and text.
    Measured in font-size units.
    Default is ``None``, which will take the value from
    :rc:`legend.handletextpad`.

borderaxespad : float or None
    The pad between the axes and legend border.
    Measured in font-size units.
    Default is ``None``, which will take the value from
    :rc:`legend.borderaxespad`.

columnspacing : float or None
    The spacing between columns.
    Measured in font-size units.
    Default is ``None``, which will take the value from
    :rc:`legend.columnspacing`.

handler_map : dict or None
    The custom dictionary mapping instances or types to a legend
    handler. This `handler_map` updates the default handler map
    found at :func:`matplotlib.legend.Legend.get_legend_handler_map`.

t   _legend_kw_doct   Legendc           B` s  e  Z d  Z i d d 6d d 6d d 6d d 6d	 d
 6d d 6d d 6d d 6d d 6d d 6d d 6Z d Z d   Z e j e e e e	 e e e e e e e e e e e d e e e e e e e e e e e d   Z
 d   Z d   Z d   Z e e e  Z d   Z e d    Z e d  Z i e j   e 6e j   e 6e j   e 6e j   e 6e j   e 6e j   e  6e j!   e" 6e j d e j#  e$ 6e j%   e& 6e j'   e( 6e j)   e* 6Z+ e, d     Z- e, d!    Z. e, d"    Z/ d#   Z0 e1 d$    Z2 e	 d%  Z3 d&   Z4 d'   Z5 d(   Z6 d)   Z7 d*   Z8 d+   Z9 d,   Z: e d-  Z; d.   Z< d/   Z= d0   Z> d1   Z? d2   Z@ e d3  ZA d4   ZB e d5  ZC d6   ZD e eE d7 d8  ZF RS(9   u6   
    Place a legend on the axes at location loc.

    i    u   besti   u   upper righti   u
   upper lefti   u
   lower lefti   u   lower righti   u   righti   u   center lefti   u   center righti   u   lower centeri	   u   upper centeri
   u   centerc         C` s   d S(   Nu   Legend(    (   R*   (    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyt   __str__/  s    c   )      C` s  d d l  m } d d l m }  t j |   |
 d: k rs | d: k	 rZ t d |  |  _ q t d t	 d  |  _ nM t
 |
 t  r t |
   |  _ d |
 k r |  j j t	 d  q n	 |
 |  _ |  j j   |  _ g  |  _ g  |  _ d: |  _ | |  _ t   }! xj d d d	 d
 d d d d d d d g D]A }" |! |" d: k rNt	 d |" }# n
 |! |" }# t |  |" |#  q'W~! g  g  }$ }% xt t | |  D]c \ }& }' t
 |& t j  r|& j d  rt j d j |' |&   q|$ j |&  |% j |'  qW|$ |% } } t |  } t |  d k  r'd } n  | |  _ |  j  d k rRt! d |   n  |	 d: k r|t" j# d; d< d= g  |  _$ n t" j% |	  |  _$ |  j& t |  j$  d }( t" j' |  j$ |(  |  j&  |  _$ d: |  _( t
 | |  rt) |  _* | |  _+ |  j, | j-  n4 t
 | |   r,t. |  _* |  j, |  n t/ d   | |  _0 | d: k ryt	 d } |  j* ry| d> k ryd } qyn  t
 | t j  r| |  j1 k r|  j* rt j d  | d! j2 |  j1  f  d } qt j d" | d! j2 |  j1  f  d } q|  j1 | } n  |  j* r7| d k r7t j d#  d } n  | |  _3 |  j4 | |  | d: k rit	 d$ } n  | d% k rt	 d& } n  | d: k rt	 d' } n  | d% k rt	 d( } n  t5 d) d? d+ d, d- d, d. | d/ | d0 |  j d1 t)  |  _6 | d: k rt	 d2 } n  | r+|  j6 j7 d3 d4 d d5 d6 n |  j6 j7 d7 d4 d |  j8 |  j6  | |  _9 | d: k rvt	 d8 |  _9 n  |  j: | | |  | d: k r| r|  j;   j< d  q|  j;   j< t	 d9  n |  j;   j< |  | |  _= |  j> |  |  j |  _? d: |  _@ d: S(@   uC   

        Parameters
        ----------
        parent : `~matplotlib.axes.Axes` or `.Figure`
            The artist that contains the legend.

        handles : sequence of `.Artist`
            A list of Artists (lines, patches) to be added to the legend.

        labels : sequence of strings
            A list of labels to show next to the artists. The length of handles
            and labels should be the same. If they are not, they are truncated
            to the smaller of both lengths.

        Other Parameters
        ----------------

        loc : int or string or pair of floats, default: 'upper right'
            The location of the legend. Possible codes are:

                ===============   =============
                Location String   Location Code
                ===============   =============
                'best'            0
                'upper right'     1
                'upper left'      2
                'lower left'      3
                'lower right'     4
                'right'           5
                'center left'     6
                'center right'    7
                'lower center'    8
                'upper center'    9
                'center'          10
                ===============   =============


            Alternatively can be a 2-tuple giving ``x, y`` of the lower-left
            corner of the legend in axes coordinates (in which case
            ``bbox_to_anchor`` will be ignored).

        bbox_to_anchor : `.BboxBase` or pair of floats
            Specify any arbitrary location for the legend in `bbox_transform`
            coordinates (default Axes coordinates).

            For example, to put the legend's upper right hand corner in the
            center of the axes the following keywords can be used::

               loc='upper right', bbox_to_anchor=(0.5, 0.5)

        ncol : integer
            The number of columns that the legend has. Default is 1.

        prop : None or :class:`matplotlib.font_manager.FontProperties` or dict
            The font properties of the legend. If None (default), the current
            :data:`matplotlib.rcParams` will be used.

        fontsize : int or float or {'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'}
            Controls the font size of the legend. If the value is numeric the
            size will be the absolute font size in points. String values are
            relative to the current default font size. This argument is only
            used if `prop` is not specified.

        numpoints : None or int
            The number of marker points in the legend when creating a legend
            entry for a `.Line2D` (line).
            Default is ``None``, which will take the value from
            :rc:`legend.numpoints`.

        scatterpoints : None or int
            The number of marker points in the legend when creating
            a legend entry for a `.PathCollection` (scatter plot).
            Default is ``None``, which will take the value from
            :rc:`legend.scatterpoints`.

        scatteryoffsets : iterable of floats
            The vertical offset (relative to the font size) for the markers
            created for a scatter plot legend entry. 0.0 is at the base the
            legend text, and 1.0 is at the top. To draw all markers at the
            same height, set to ``[0.5]``. Default is ``[0.375, 0.5, 0.3125]``.

        markerscale : None or int or float
            The relative size of legend markers compared with the originally
            drawn ones.
            Default is ``None``, which will take the value from
            :rc:`legend.markerscale`.

        markerfirst : bool
            If *True*, legend marker is placed to the left of the legend label.
            If *False*, legend marker is placed to the right of the legend
            label.
            Default is *True*.

        frameon : None or bool
            Control whether the legend should be drawn on a patch
            (frame).
            Default is ``None``, which will take the value from
            :rc:`legend.frameon`.

        fancybox : None or bool
            Control whether round edges should be enabled around the
            :class:`~matplotlib.patches.FancyBboxPatch` which makes up the
            legend's background.
            Default is ``None``, which will take the value from
            :rc:`legend.fancybox`.

        shadow : None or bool
            Control whether to draw a shadow behind the legend.
            Default is ``None``, which will take the value from
            :rc:`legend.shadow`.

        framealpha : None or float
            Control the alpha transparency of the legend's background.
            Default is ``None``, which will take the value from
            :rc:`legend.framealpha`.  If shadow is activated and
            *framealpha* is ``None``, the default value is ignored.

        facecolor : None or "inherit" or a color spec
            Control the legend's background color.
            Default is ``None``, which will take the value from
            :rc:`legend.facecolor`.  If ``"inherit"``, it will take
            :rc:`axes.facecolor`.

        edgecolor : None or "inherit" or a color spec
            Control the legend's background patch edge color.
            Default is ``None``, which will take the value from
            :rc:`legend.edgecolor` If ``"inherit"``, it will take
            :rc:`axes.edgecolor`.

        mode : {"expand", None}
            If `mode` is set to ``"expand"`` the legend will be horizontally
            expanded to fill the axes area (or `bbox_to_anchor` if defines
            the legend's size).

        bbox_transform : None or :class:`matplotlib.transforms.Transform`
            The transform for the bounding box (`bbox_to_anchor`). For a value
            of ``None`` (default) the Axes'
            :data:`~matplotlib.axes.Axes.transAxes` transform will be used.

        title : str or None
            The legend's title. Default is no title (``None``).

        borderpad : float or None
            The fractional whitespace inside the legend border.
            Measured in font-size units.
            Default is ``None``, which will take the value from
            :rc:`legend.borderpad`.

        labelspacing : float or None
            The vertical space between the legend entries.
            Measured in font-size units.
            Default is ``None``, which will take the value from
            :rc:`legend.labelspacing`.

        handlelength : float or None
            The length of the legend handles.
            Measured in font-size units.
            Default is ``None``, which will take the value from
            :rc:`legend.handlelength`.

        handletextpad : float or None
            The pad between the legend handle and text.
            Measured in font-size units.
            Default is ``None``, which will take the value from
            :rc:`legend.handletextpad`.

        borderaxespad : float or None
            The pad between the axes and legend border.
            Measured in font-size units.
            Default is ``None``, which will take the value from
            :rc:`legend.borderaxespad`.

        columnspacing : float or None
            The spacing between columns.
            Measured in font-size units.
            Default is ``None``, which will take the value from
            :rc:`legend.columnspacing`.

        handler_map : dict or None
            The custom dictionary mapping instances or types to a legend
            handler. This `handler_map` updates the default handler map
            found at :func:`matplotlib.legend.Legend.get_legend_handler_map`.

        Notes
        -----

        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.
        i    (   t   Axes(   t   Figuret   sizeu   legend.fontsizeu   sizeu	   numpointsu   markerscaleu   shadowu   columnspacingu   scatterpointsu   handleheightu	   borderpadu   labelspacingu   handlelengthu   handletextpadu   borderaxespadu   legend.u   _uV   The handle {!r} has a label of {!r} which cannot be automatically added to the legend.i   i   u    numpoints must be > 0; it was %dg      @g       @g      @g      @u,   Legend needs either Axes or Figure as parentu
   legend.locu   bestu   upper rightuL   Unrecognized location "%s". Falling back on "best"; valid locations are
	%s
u   
	uS   Unrecognized location "%s". Falling back on "upper right"; valid locations are
	%s
ui   Automatic legend placement (loc="best") not implemented for figure legend. Falling back on "upper right".u   legend.facecoloru   inheritu   axes.facecoloru   legend.edgecoloru   axes.edgecolort   xyg        R6   g      ?R7   t	   facecolort	   edgecolort   mutation_scalet   snapu   legend.fancyboxu   roundt   padt   rounding_sizeg?u   squareu   legend.frameonu   legend.framealphaNg      ?g      ?g      ?(   i    u   best(   g        g        (A   t   matplotlib.axesRI   t   matplotlib.figureRJ   R   R(   R9   R
   t   propR   t
   isinstancet   dictt   set_sizet   get_size_in_pointst	   _fontsizet   textst   legendHandlest   _legend_title_boxt   _custom_handler_mapt   localst   setattrt   zipt   sixt   string_typest
   startswitht   warningst   warnt   formatt   appendt   listt   lent   _ncolt	   numpointsR'   t   npt   arrayt   _scatteryoffsetst   asarrayt   scatterpointst   tileR)   t   Truet   isaxesR?   t
   set_figuret   figureRE   t	   TypeErrort   parentt   codest   joint   _modeR8   R   t   legendPatcht   set_boxstylet   _set_artist_propst
   _drawFramet   _init_legend_boxt	   get_framet	   set_alphaR<   t	   set_titlet   _last_fontsize_pointst
   _draggable()   R*   Rx   t   handlest   labelst   locRl   t   markerscalet   markerfirstRq   t   scatteryoffsetsRU   t   fontsizet	   borderpadt   labelspacingt   handlelengtht   handleheightt   handletextpadt   borderaxespadt   columnspacingt   ncolt   modet   fancyboxt   shadowt   titlet
   framealphaRN   RM   t   bbox_to_anchort   bbox_transformt   frameont   handler_mapRI   RJ   t   locals_viewt   namet   valuet   _labt   _handt   labelt   handlet   reps(    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyR(   2  s    								
							
								
		c         C` s?   | j  |  j  |  j r( |  j | _ n  | j |  j    d S(   uF   
        Set the boilerplate props for artists added to axes.
        N(   Ru   Rv   Rt   R?   t   set_transformt   get_transform(   R*   t   a(    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyR~     s    	c         C` s)   | |  _  t |  _ |  j j |  j  d  S(   N(   t	   _loc_realRs   t   staleR)   t
   set_offsett   _findoffset(   R*   R   (    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyt   _set_loc  s    		c         C` s   |  j  S(   N(   R   (   R*   (    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyt   _get_loc  s    c         C` s   |  j  d k r- |  j | | |  \ } } n |  j  t j j   k r t j d d | |  } |  j |  j  | |  j   |  \ } } nD |  j  \ }	 }
 |  j   } | j	 | j
 |	 | j | j |
 } } | | | | f S(   u%   Helper function to locate the legend.i    (   R<   t   _find_best_positionRG   Ry   t   valuesR   t   from_boundst   _get_anchored_bboxR5   t   x0R6   t   y0R7   (   R*   R6   R7   t   xdescentt   ydescentt   renderert   xt   yR=   t   fxt   fy(    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyR     s    	)c         C` s1  |  j    s d S| j d  | j |  j  } |  j d k rv d |  j |  j | } |  j j |  j	   j
 |  n  |  j j |  } |  j j | j | j | j
 | j  |  j j |  |  j r|  j r t |  j d d  } | j |  n  |  j j |  n  |  j j |  | j d  t |  _ d S(   u+   Draw everything that belongs to the legend.Nu   legendu   expandi   i(   u   expand(   t   get_visiblet
   open_groupt   points_to_pixelsRZ   R{   R   R   R)   t	   set_widthR5   R6   t   get_window_extentR|   t
   set_boundsR   R   R7   t   set_mutation_scaleR   R   R   t   drawt   close_groupRE   R   (   R*   R   R   RQ   R=   R   (    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyR     s&     		c         C` s'   | d k r |  j S| j |  j  Sd S(   um   
        Return the approximate height of the text. This is used to place
        the legend handle.
        N(   R9   RZ   R   (   R*   R   (    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyt   _approx_text_height  s    t   update_funcc         C` s   |  j  S(   uF   
        A class method that returns the default handler map.
        (   t   _default_handler_map(   t   cls(    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyt   get_default_handler_map7  s    c         C` s   | |  _  d S(   u@   
        A class method to set the default handler map.
        N(   R   (   R   R   (    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyt   set_default_handler_map>  s    c         C` s   |  j  j |  d S(   uC   
        A class method to update the default handler map.
        N(   R   R+   (   R   R   (    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyt   update_default_handler_mapE  s    c         C` s=   |  j    } |  j r5 | j   } | j |  j  | S| Sd S(   u)   
        Return the handler map.
        N(   R   R^   t   copyR+   (   R*   t   default_handler_mapt   hm(    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyt   get_legend_handler_mapL  s    	c         C` sp   t  |  r/ y |  | SWq/ t k
 r+ q/ Xn  x: t |  j   D]& } y |  | SWqB t k
 rg qB XqB Wd S(   u  
        Return a legend handler from *legend_handler_map* that
        corresponds to *orig_handler*.

        *legend_handler_map* should be a dictionary object (that is
        returned by the get_legend_handler_map method).

        It first checks if the *orig_handle* itself is a key in the
        *legend_hanler_map* and return the associated value.
        Otherwise, it checks for each of the classes in its
        method-resolution-order. If no matching key is found, it
        returns ``None``.
        N(   R	   t   KeyErrort   typet   mroR9   (   t   legend_handler_mapt   orig_handlet   handle_type(    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyt   get_legend_handlerZ  s    c   !      C` s  |  j  } g  } g  } g  } t d d d d d |  j  } d |  j   |  j d }	 |  j   |  j |	 }
 |  j   } x t | |  D] \ } } |  j | |  } | d k r t	 j
 d j |   | j d  q t | d	 | d
 t d t } t d |  j | d |
 d d d |	  } | j | j  | j | j |  | | |   | j | | f  q W| rt |  j t |   } t t |  |  \ } } | | } | d g | | g | } t j d g t j |  d  g  } t | |  } n g  } g  } x | D] \ } } g  | | | | !D]L \ } } t d d d |  j | d | ra| | g n	 | | g d d  ^ q*} | r| d j   d j t  n | d j   d j t  | rd n d } | j t d d d |  j  | d | d |   qW|  j! d k rd n d } |  j" | }  t d d d |  d d d | d |  |  _# t d  |  _$ t d |  j% | d |  j  | d d d |  j$ |  j# g  |  _& |  j& j' |  j(  | |  _) | |  _* d S(   u   
        Initialize the legend_box. The legend_box is an instance of
        the OffsetBox, which is packed with legend handles and
        texts. Once packed, their location is calculated during the
        drawing time.
        t   verticalalignmentu   baselinet   horizontalalignmentu   leftt   fontpropertiesgffffff?gffffff?u   Legend does not support {!r} instances.
A proxy artist may be used instead.
See: http://matplotlib.org/users/legend_guide.html#creating-artists-specifically-for-adding-to-the-legend-aka-proxy-artistst	   textpropst   multilinebaselinet   minimumdescentR6   R7   R   g        R   i   i    iRQ   t   sept   childrent   alignu   rightu   expandu   fixedR   u    u   centerN(+   RZ   RW   RU   R   R   R   Ra   R   R9   Re   Rf   Rg   Rh   R   Rs   R   R   t   _textt   legend_artistt   minRk   Rj   t   divmodRm   t   concatenatet   cumsumR   R   t   get_childrent   set_minimumdescentRE   R   R   R{   R   t   _legend_handle_boxR]   R   R)   Ru   Rv   R[   R\   (!   R*   R   R   R   R   t	   text_listt   handle_listt   handles_and_labelst
   label_propt   descentR7   R   R   t   labt   handlert   textboxt	   handleboxR   t   nrowst   num_largecolt   num_smallcolt   rows_per_colt
   start_idxst   colst	   columnboxt   i0t   dit   ht   tt	   itemBoxest	   alignmentR   R   (    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyR   w  s|    	
	
	
%a	c         C` s  |  j  s t  |  j } g  } g  } g  } xZ | j D]O } t | t  sO t  | j   } | j   } | j |  } | j	 |  q4 Wx | j
 D]} } t | t  s t  t | t  r | j   }	 | j	 | j   j |	   q | j   }	 | j	 | j   j |	   q Wx_ | j D]T } | j   \ }	 }
 } } t |  rx' |
 j |  D] } | j	 |  qVWqqWy) t j g  | D] } | j ^ q } Wn  t k
 rt j g   } n X| | | | g S(   u{  
        Returns list of vertices and extents covered by the plot.

        Returns a two long list.

        First element is a list of (x, y) vertices (in
        display-coordinates) covered by all the lines and line
        collections, in the legend's handles.

        Second element is a list of bounding boxes for all the patches in
        the legend's handles.
        (   Rt   t   AssertionErrorRx   t   linesRV   R   t   get_pathR   t   transform_pathRh   t   patchesR   R   t   get_data_transformt   get_bboxt   transformedt   get_extentst   collectionst   _prepare_pointsRj   t	   transformRm   R   t   verticesR'   Rn   (   R*   t   axt   bboxesR   t   offsetsR   t   patht   transt   tpathR
  t   transOffsett   hoffsetst   pathst   offsett   lR  (    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyt   _auto_legend_data  s8    	 )c         C` s   |  j  |  d S(   u^   
        Set draw frame to b.

        Parameters
        ----------
        b : bool
        N(   t   set_frame_on(   R*   t   b(    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyt
   draw_frame$  s    c         C` s9   g  } |  j  r" | j |  j   n  | j |  j    | S(   u   Return a list of child artists.(   R)   Rh   R   (   R*   R   (    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyR   .  s
    	c         C` s   |  j  S(   uV   
        Return the `~.patches.Rectangle` instances used to frame the legend.
        (   R|   (   R*   (    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyR   7  s    c         C` s)   g  |  j  D] } t | t  r
 | ^ q
 S(   u:   Return a list of `~.lines.Line2D` instances in the legend.(   R\   RV   R   (   R*   R   (    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyt	   get_lines=  s    c         C` s2   t  d g  |  j D] } t | t  r | ^ q  S(   u;   Return a list of `~.patches.Patch` instances in the legend.u   Patch(   R   R\   RV   R   (   R*   R   (    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyt   get_patchesA  s    c         C` s   t  d |  j  S(   u7   Return a list of `~.text.Text` instances in the legend.u   Text(   R   R[   (   R*   (    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyt	   get_textsG  s    c         C` s   |  j  j j |  | d k	 rS t | t  r= t |   } n  |  j  j j |  n  | rl |  j  j t	  n |  j  j t
  t	 |  _ d S(   uk   
        Set the legend title. Fontproperties can be optionally set
        with *prop* parameter.
        N(   R]   R   t   set_textR9   RV   RW   R
   t   set_fontpropertiest   set_visibleRs   RE   R   (   R*   R   RU   (    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyR   K  s    c         C` s
   |  j  j S(   u1   Return the `.Text` instance for the legend title.(   R]   R   (   R*   (    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyt	   get_title]  s    c         O` s   |  j  j | |   S(   u   Return extent of the legend.(   R|   R   (   R*   t   argst   kwargs(    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyR   a  s    c         C` s   |  j  S(   u*   Get whether the legend box patch is drawn.(   R   (   R*   (    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyt   get_frame_one  s    c         C` s   | |  _  t |  _ d S(   u   
        Set whether the legend box patch is drawn.

        Parameters
        ----------
        b : bool
            .. ACCEPTS: bool
        N(   R   Rs   R   (   R*   R  (    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyR  i  s    		c         C` s$   |  j  d k r |  j j S|  j  Sd S(   u4   Return the bbox that the legend will be anchored to.N(   t   _bbox_to_anchorR9   Rx   R=   (   R*   (    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyR5   u  s    
c         C` s   | d k r d |  _ d St | t  r4 | |  _ nu y t |  } Wn' t k
 rm t d t |    n X| d k r | d | d d d g } n  t j	 |   |  _ | d k r t
 |  j j  } n  t |  j |  |  _ t |  _ d S(   ub  
        Set the bbox that the legend will be anchored to.

        *bbox* can be

        - A `.BboxBase` instance
        - A tuple of ``(left, bottom, width, height)`` in the given transform
          (normalized axes coordinate if None)
        - A tuple of ``(left, bottom)`` where the width and height will be
          assumed to be zero.
        Nu   Invalid argument for bbox : %si   i    i   (   R9   R%  RV   R   Rj   Rw   R'   t   strR   R   R   Rx   R=   R   Rs   R   (   R*   R=   R
  R  (    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyR8   |  s"    		c         C` s   | t  d d  k s t  t  d  \ } } } } }	 }
 } } } } } i
 d | 6d | 6d | 6d |	 6d |
 6d | 6d | 6d	 | 6d
 | 6d | 6} | | } | j |  j  } | j |  j |  } | j | d | } | j | j f S(   u  
        Place the *bbox* inside the *parentbbox* according to a given
        location code. Return the (x,y) coordinate of the bbox.

        - loc: a location code in range(1, 11).
          This corresponds to the possible values for self._loc, excluding
          "best".

        - bbox: bbox to be placed, display coordinate units.
        - parentbbox: a parent box which will contain the bbox. In
            display coordinates.
        i   i   u   NEu   NWu   SWu   SEu   Eu   Wu   Su   Nu   Ct	   container(	   t   rangeR   R   RZ   t   paddedR   t   anchoredR   R   (   R*   R   R=   t
   parentbboxR   t   BESTt   URt   ULt   LLt   LRt   Rt   CLt   CRt   LCt   UCt   Ct   anchor_coefst   cR   R'  t   anchored_box(    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyR     s"    -


c         ` sr  |  j  s t  |  j   \ } } } } t j d d | |  }	 | d k r g  t d t |  j   D]$ }
 |  j	 |
 |	 |  j
   |  ^ qd } n  g  } x t |  D] \ } \ } } t j | | | |    d }   j |    j |    j |  t   f d   | D  } | d k r-| | f S| j | | | | f f  q Wt |  \ } } \ } } | | f S(   u   
        Determine the best location to place the legend.

        *consider* is a list of ``(x, y)`` pairs to consider as a potential
        lower-left corner of the legend. All are display coords.
        i    i   c         3` s$   |  ] } | j    d  t Vq d S(   t   filledN(   t   intersects_bboxRE   (   t   .0t   line(   t	   legendBox(    s0   lib/python2.7/site-packages/matplotlib/legend.pys	   <genexpr>  s   N(   Rt   R   R  R   R   R9   R(  Rj   Ry   R   R5   t	   enumeratet   count_containst   count_overlapst   sumRh   R   (   R*   R6   R7   R   t   considert   vertsR  R   R  R=   R   t
   candidatest   idxR  R  t   badnesst   _(    (   R>  s0   lib/python2.7/site-packages/matplotlib/legend.pyR     s"    C5
 c         C` s   |  j  j |  S(   N(   R|   R,   (   R*   t   event(    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyR,     s    u   locc         C` s   |  j  d k	 } | d k r% | } n  | rX |  j  d k r t |  | d | |  _  q n( |  j  d k	 rw |  j  j   n  d |  _  |  j  S(   u?  
        Set the draggable state -- if state is

          * None : toggle the current state

          * True : turn draggable on

          * False : turn draggable off

        If draggable is on, you can drag the legend on the canvas with
        the mouse. The `.DraggableLegend` helper instance is returned if
        draggable is on.

        The update parameter control which parameter of the legend changes
        when dragged. If update is "loc", the *loc* parameter of the legend
        is changed. If "bbox", the *bbox_to_anchor* parameter is changed.
        R+   N(   R   R9   R#   t
   disconnect(   R*   t   stateR$   R+   t   is_draggable(    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyt	   draggable  s    
	(G   RC   RD   t   __doc__Ry   t   zorderRH   R   t   dedent_interpdR9   Rs   R(   R~   R   R   t   propertyR<   R   R   R   R   R"   t   HandlerStemR!   t   HandlerErrorbarR   t   HandlerLine2DR   t   HandlerPatchR   t   HandlerLineCollectionR   t   HandlerRegularPolyCollectionR   t   HandlerCircleCollectionR   t   update_from_first_childR    t   HandlerTupleR:   t   HandlerPathCollectionR   t   HandlerPolyCollectionR   R   t   classmethodR   R   R   R   t   staticmethodR   R   R  R  R   R   R  R  R  R   R!  R   R$  R  R5   R8   R   R   R,   RE   RM  (    (    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyRG     s   

	 r				#		y	4	
											#	#'	c   	      c` s  g  } xx |  D]p } | | j  | j | j | j 7} t | d  r x6 | j D]( } | | j  | j | j | j 7} qN Wq q Wt j   } | d k	 r | j	   } | j
 |  n  t j } x= | D]5 } | j   } | d k r | | |  r | Vq q Wd S(   uU   
    Return a generator of artists that can be used as handles in
    a legend.

    u	   parasitesu
   _nolegend_N(   R   R  R  t
   containerst   hasattrt	   parasitesRG   R   R9   R   R+   R   t	   get_label(	   t   axsR   t   handles_originalR  t   axxR   t   has_handlerR   R   (    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyt   _get_legend_handles  s"    *	c         C` so   g  } g  } xV t  |  |  D]E } | j   } | r | j d  r | j |  | j |  q q W| | f S(   uA   
    Return handles and labels for legend, internal method.

    u   _(   Rg  Rb  Rd   Rh   (   Rc  R   R   R   R   R   (    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyt   _get_legend_handles_labels1  s    c   
      O` s  t  j t  } | j d i   p$ i  } | j d d
  } | j d d
  } d } | d
 k	 si | d
 k	 r t |  r t j d  n  | r | r t	 t	 | |    \ } } nP| d
 k	 r | d
 k r g  | D] } | j
   ^ q } n| d
 k	 r5| d
 k r5g  t	 t |  |  |  D] \ } }	 | ^ q} n t |  d k rut |  |  \ } } | s| j d  qn t |  d k r| \ } g  t	 t |  |  |  D] \ } }	 | ^ q} n; t |  d k r| d  \ } } | d } n t d	   | | | | f S(   u   
    Get the handles and labels from the calls to either ``figure.legend``
    or ``axes.legend``.

    ``axs`` is a list of axes (to get legend artists from)
    u   handler_mapu   handlesu   labelsuM   You have mixed positional and keyword arguments, some input may be discarded.i    u.   No handles with labels found to put in legend.i   i   u   Invalid arguments to legend.N(    (   t   loggingt	   getLoggerRC   t   gett   popR9   Rj   Re   Rf   Ra   Rb  Rg  Rh  t   warningRw   (
   Rc  R"  R#  t   logt   handlersR   R   t
   extra_argsR   R   (    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyt   _parse_legend_argsA  s6    $"1	1(@   RN  t
   __future__R    R   R   R   Rb   Ri  Re   t   numpyRm   t
   matplotlibR   R   t   matplotlib.artistR   R   t   matplotlib.cbookR   R	   t   matplotlib.colorst   colorst   matplotlib.font_managerR
   t   matplotlib.linesR   t   matplotlib.patchesR   R   R   R   t   matplotlib.collectionsR   R   R   R   R   t   matplotlib.transformsR   R   R   R   R   t   matplotlib.offsetboxR   R   R   R   R   t   matplotlib.containerR   R    R!   t    R"   R#   RF   t   interpdR+   RG   R9   Rg  Rh  Rq  (    (    (    s0   lib/python2.7/site-packages/matplotlib/legend.pyt   <module>   s<   ""("   