ó
±éRc           @   sV  d  Z  d d l Z d d l m Z d d l m Z d d l j Z	 d „  Z
 d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   sZ  
This module defines default legend handlers.

Legend handlers are expected to be a callable object with a following
signature. ::

    legend_handler(legend, orig_handle, fontsize, handlebox)

Where *legend* is the legend itself, *orig_handle* is the original
plot, *fontsize* is the fontsize in pixles, and *handlebox* is a
OffsetBox instance. Within the call, you should create relevant
artists (using relevant properties from the *legend* and/or
*orig_handle*) and add them into the handlebox. The artists needs to
be scaled according to the fontsize (note that the size is in pixel,
i.e., this is dpi-scaled value).

This module includes definition of several legend handler classes
derived from the base class (HandlerBase) with a following method.

    def __call__(self, legend, orig_handle,
                 fontsize,
                 handlebox):


iÿÿÿÿN(   t   Line2D(   t	   Rectanglec         C   s   |  j  | j ƒ  d ƒ d  S(   Ni    (   t   update_fromt   get_children(   t   tgtt   src(    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyt   update_from_first_child"   s    t   HandlerBasec           B   sV   e  Z d  Z d d d	 d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(
   s   
    A Base class for default legend handlers.

    The derived classes are meant to override *create_artists* method, which
    has a following signature.::

      def create_artists(self, legend, orig_handle,
                         xdescent, ydescent, width, height, fontsize,
                         trans):

    The overridden method needs to create artists of the given
    transform that fits in the given dimension (xdescent, ydescent,
    width, height) that are scaled by fontsize if necessary.

    g        c         C   s    | | |  _  |  _ | |  _ d  S(   N(   t   _xpadt   _ypadt   _update_prop_func(   t   selft   xpadt   ypadt   update_func(    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyt   __init__6   s    c         C   s6   |  j  d  k r" |  j | | ƒ n |  j  | | ƒ d  S(   N(   R
   t   Nonet   _default_update_prop(   R   t   legend_handlet   orig_handle(    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyt   _update_prop:   s    c         C   s   | j  | ƒ d  S(   N(   R   (   R   R   R   (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR   @   s    c         C   s;   |  j  | | ƒ | j | ƒ | j d  ƒ | j d  ƒ d  S(   N(   R   t   _set_artist_propst   set_clip_boxR   t   set_clip_path(   R   R   R   t   legend(    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyt   update_propC   s    c         C   sT   | |  j  | } | |  j | } | |  j  | } | |  j | } | | | | f S(   N(   R   R	   (   R   R   R   t   xdescentt   ydescentt   widtht   heightt   fontsize(    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyt   adjust_drawing_areaK   s
    c      	   C   s§   | j  | j | j | j f \ } } } } |  j | | | | | | | ƒ \ } } } } |  j | | | | | | | | j ƒ  ƒ }	 x |	 D] }
 | j |
 ƒ qˆ W|	 d S(   sa   
        x, y, w, h in display coordinate w/ default dpi (72)
        fontsize in points
        i    (   R   R   R   R   R   t   create_artistst   get_transformt
   add_artist(   R   R   R   R   t	   handleboxR   R   R   R   t   a_listt   a(    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyt   __call__T   s    c	   	      C   s   t  d ƒ ‚ d  S(   Ns   Derived must override(   t   NotImplementedError(	   R   R   R   R   R   R   R   R   t   trans(    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR    p   s    N(   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R&   R    (    (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR   &   s   						t   HandlerNpointsc           B   s)   e  Z d  d d „ Z d „  Z d „  Z RS(   g333333Ó?c         K   s&   t  j |  | � | |  _ | |  _ d  S(   N(   R   R   t
   _numpointst   _marker_pad(   R   t
   marker_padt	   numpointst   kw(    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR   x   s    	c         C   s!   |  j  d  k r | j S|  j  Sd  S(   N(   R-   R   R0   (   R   R   (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyt   get_numpoints~   s    c   
      C   s”   |  j  | ƒ } | d k rP t j | |  j | | |  j | | ƒ } | }	 n: | d k rŠ t j | | d ƒ } d | d | g }	 n  | |	 f S(   Ni   i   g      à?(   R2   t   npt   linspaceR.   (
   R   R   R   R   R   R   R   R0   t   xdatat   xdata_marker(    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyt	   get_xdata„   s    		N(   R)   R*   R   R   R2   R7   (    (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR,   w   s   	t   HandlerNpointsYoffsetsc           B   s    e  Z d d d  „ Z d „  Z RS(   c         K   s#   t  j |  d | | �| |  _ d  S(   NR0   (   R,   R   t	   _yoffsets(   R   R0   t   yoffsetsR1   (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR   –   s    c         C   s9   |  j  d  k r | | j } n | t j |  j  ƒ } | S(   N(   R9   R   t   _scatteryoffsetsR3   t   asarray(   R   R   R   R   R   R   R   t   ydata(    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyt	   get_ydataš   s    N(   R)   R*   R   R   R>   (    (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR8   •   s   t   HandlerLine2Dc           B   s&   e  Z d  Z d d d „ Z d „  Z RS(   s&   
    Handler for Line2D instances
    g333333Ó?c         K   s    t  j |  d | d | | �d  S(   NR/   R0   (   R,   R   (   R   R/   R0   R1   (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR   §   s    c	         C   s  |  j  | | | | | | ƒ \ }	 }
 | | d t j |	 j t ƒ } t |	 | ƒ } |  j | | | ƒ | j d ƒ | j d ƒ t |
 | t	 |
 ƒ  ƒ } |  j | | | ƒ | j
 d ƒ | j d k rì | j ƒ  | j } | j | ƒ n  | | _ | j | ƒ | j | ƒ | | g S(   Ng       @t   defaultt    R   i   (   R7   R3   t   onest   shapet   floatR    R   t   set_drawstylet
   set_markert   lent   set_linestylet   markerscalet   get_markersizet   set_markersizet
   _legmarkert   set_transform(   R   R   R   R   R   R   R   R   R(   R5   R6   R=   t   leglinet   legline_markert   newsz(    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR    ª   s"    !	N(   R)   R*   R+   R   R   R    (    (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR?   £   s   t   HandlerPatchc           B   s,   e  Z d  Z d d „ Z d „  Z d „  Z RS(   s   
    Handler for Patches
    c         K   s   t  j |  | � | |  _ d  S(   N(   R   R   t   _patch_func(   R   t
   patch_funcR1   (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR   Ì   s    c   	      C   so   |  j  d  k r5 t d | | f d | d | ƒ } n6 |  j  d | d | d | d | d | d | d | ƒ } | S(	   Nt   xyR   R   R   R   R   R   R   (   RR   R   R   (	   R   R   R   R   R   R   R   R   t   p(    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyt   _create_patchÑ   s    c	   
      C   sH   |  j  | | | | | | | ƒ }	 |  j |	 | | ƒ |	 j | ƒ |	 g S(   N(   RV   R   RM   (
   R   R   R   R   R   R   R   R   R(   RU   (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR    Ü   s
    N(   R)   R*   R+   R   R   RV   R    (    (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyRQ   È   s   	t   HandlerLineCollectionc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s%   
    Handler for LineCollections
    c         C   s!   |  j  d  k r | j S|  j  Sd  S(   N(   R-   R   t   scatterpoints(   R   R   (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR2   ë   s    c         C   sr   | j  ƒ  d } | j ƒ  d } | j ƒ  d } | j | ƒ | j | ƒ | d d  k	 rn | j | d ƒ n  d  S(   Ni    i   (   t   get_linewidtht
   get_dashest
   get_colorst	   set_colort   set_linewidthR   t
   set_dashes(   R   R   R   t   lwt   dashest   color(    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR   ñ   s    c	         C   s{   |  j  | | | | | | ƒ \ }	 }
 | | d t j |	 j t ƒ } t |	 | ƒ } |  j | | | ƒ | j | ƒ | g S(   Ng       @(   R7   R3   RB   RC   RD   R    R   RM   (   R   R   R   R   R   R   R   R   R(   R5   R6   R=   RN   (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR    ú   s    !(   R)   R*   R+   R2   R   R    (    (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyRW   ç   s   			t   HandlerRegularPolyCollectionc           B   sJ   e  Z d  Z d d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   s-   
    Handler for RegularPolyCollections.
    c         K   s#   t  j |  d | | �| |  _ d  S(   NR:   (   R8   R   t   _sizes(   R   R:   t   sizesR1   (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR     s    c         C   s!   |  j  d  k r | j S|  j  Sd  S(   N(   R-   R   RX   (   R   R   (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR2     s    c         C   sµ   |  j  d  k r¨ t | j ƒ  ƒ | j d } t | j ƒ  ƒ | j d }	 |  j | ƒ }
 |
 d k  r~ d | |	 | |	 g } q± | |	 } | t j d d |
 ƒ |	 } n	 |  j  } | S(   Ni   i   g      à?i    i   (	   Rc   R   t   maxt	   get_sizesRI   t   minR2   R3   R4   (   R   R   R   R   R   R   R   R   t   size_maxt   size_minR0   Rd   t   rng(    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyRf     s    
 	c         C   s>   |  j  | | ƒ | j | j ƒ | j d  ƒ | j d  ƒ d  S(   N(   R   t
   set_figuret   figureR   R   R   (   R   R   R   R   (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR   )  s    c      
   C   s:   t  | ƒ | j ƒ  d | j ƒ  d | d | d | ƒ} | S(   Nt   rotationRd   t   offsetst   transOffset(   t   typet   get_numsidest   get_rotation(   R   R   Rd   Rn   Ro   RU   (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyt   create_collection2  s    	c	         C   s­   |  j  | | | | | | ƒ \ }	 }
 |  j | | | | | | ƒ } |  j | | | | | | | ƒ } |  j | | d t |
 | ƒ d | ƒ} |  j | | | ƒ | | _ | g S(   NRn   Ro   (   R7   R>   Rf   Rs   t   zipR   t   _transOffset(   R   R   R   R   R   R   R   R   R(   R5   R6   R=   Rd   RU   (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR    ;  s    		N(
   R)   R*   R+   R   R   R2   Rf   R   Rs   R    (    (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyRb     s   						t   HandlerPathCollectionc           B   s   e  Z d  Z d „  Z RS(   s@   
    Handler for PathCollections, which are used by scatter
    c         C   s5   t  | ƒ | j ƒ  d g d | d | d | ƒ} | S(   Ni    Rd   Rn   Ro   (   Rp   t	   get_paths(   R   R   Rd   Rn   Ro   RU   (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyRs   T  s
    	(   R)   R*   R+   Rs   (    (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyRv   P  s   t   HandlerCircleCollectionc           B   s   e  Z d  Z d „  Z RS(   s'   
    Handler for CircleCollections
    c         C   s"   t  | ƒ | d | d | ƒ} | S(   NRn   Ro   (   Rp   (   R   R   Rd   Rn   Ro   RU   (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyRs   a  s    	(   R)   R*   R+   Rs   (    (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyRx   ]  s   t   HandlerErrorbarc           B   s5   e  Z d  Z d d d d d „ Z d „  Z d „  Z RS(   s   
    Handler for Errorbars
    g      à?g333333Ó?c         K   s2   | |  _  | |  _ t j |  d | d | | �d  S(   NR/   R0   (   t
   _xerr_sizet
   _yerr_sizeR?   R   (   R   t	   xerr_sizet	   yerr_sizeR/   R0   R1   (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR   m  s    		c   	      C   s<   |  j  | } |  j d  k r% | } n |  j | } | | f S(   N(   Rz   R{   R   (	   R   R   R   R   R   R   R   R|   R}   (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyt   get_err_sizev  s
    	c	         C   sò  | \ }	 }
 } |  j  | | | | | | ƒ \ } } | | d t j | j t ƒ } t | | ƒ } t j | ƒ } t j | t | ƒ  ƒ } |  j | | | | | | ƒ \ } } t | | ƒ } |	 d  k rç | j
 t ƒ | j
 t ƒ n |  j | |	 | ƒ | j d ƒ | j d ƒ |  j | |	 | ƒ | j d ƒ | j d k rf| j ƒ  | j } | j | ƒ n  g  } g  } | j r„g  t | | ƒ D], \ } } | | | f | | | f f ^ q‹} t j | ƒ } |  j | | d | ƒ | j | ƒ |
 r„t | | | ƒ } t | | | ƒ } |  j | |
 d | ƒ |  j | |
 d | ƒ | j d ƒ | j d ƒ | j | ƒ | j | ƒ q„n  | j r–g  t | | ƒ D], \ } } | | | f | | | f f ^ q�} t j | ƒ } |  j | | d | ƒ | j | ƒ |
 r–t | | | ƒ } t | | | ƒ } |  j | |
 d | ƒ |  j | |
 d | ƒ | j d ƒ | j d ƒ | j | ƒ | j | ƒ q–n  g  } | j | ƒ | j | ƒ | j | ƒ | j | ƒ x | D] } | j | ƒ q×W| S(   Ng       @R@   R   i   i    t   |t   _(   R7   R3   RB   RC   RD   R    R<   RG   R~   R   t   set_visiblet   FalseR   RE   RF   RH   RI   RJ   RK   t   has_xerrRt   t   mcollt   LineCollectiont   appendt   has_yerrt   extendRM   (   R   R   R   R   R   R   R   R   R(   t	   plotlinest   caplinest   barlinecolsR5   R6   R=   RN   t   ydata_markerR|   R}   RO   RP   t   handle_barlinecolst   handle_caplinest   xt   yt   vertst   collt   capline_leftt   capline_rightt   artistst   artist(    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR    €  sz    !	?	?N(   R)   R*   R+   R   R   R~   R    (    (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyRy   i  s
   	
t   HandlerStemc           B   s5   e  Z d  Z d d d d d „ Z d „  Z d „  Z RS(   s   
    Handler for Errorbars
    g333333Ó?c      	   K   s/   t  j |  d | d | d | | �| |  _ d  S(   NR/   R0   R:   (   R8   R   t   _bottom(   R   R/   R0   t   bottomR:   R1   (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR   Ý  s
    c         C   sA   |  j  d  k r' | d | j d } n | t j |  j  ƒ } | S(   Ng      à?(   R9   R   R;   R3   R<   (   R   R   R   R   R   R   R   R=   (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR>   æ  s    c	         C   s¤  | \ }	 }
 } |  j  | | | | | | ƒ \ } } |  j | | | | | | ƒ } |  j d  k ri d } n	 |  j } t | | t | ƒ  ƒ } |  j | |	 | ƒ g  } xE t | | ƒ D]4 \ } } t | | g | | g ƒ } | j | ƒ q´ Wx0 t | |
 ƒ D] \ } } |  j | | | ƒ qü Wt t	 j
 | ƒ t	 j | ƒ g | | g ƒ } |  j | | | ƒ | g } | j | ƒ | j | ƒ x | D] } | j | ƒ q‰W| S(   Ng        (   R7   R>   R˜   R   R    RG   R   Rt   R†   R3   t   amint   amaxRˆ   RM   (   R   R   R   R   R   R   R   R   R(   t
   markerlinet	   stemlinest   baselineR5   R6   R=   R™   t   leg_markerlinet   leg_stemlinest   thisxt   thisyt   lt   lmt   mt   leg_baselineR•   R–   (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR    î  s2    			N(   R)   R*   R+   R   R   R>   R    (    (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR—   Ù  s
   	t   HandlerTuplec           B   s    e  Z d  Z d „  Z d „  Z RS(   s   
    Handler for Tuple
    c         K   s   t  j |  | � d  S(   N(   R   R   (   R   t   kwargs(    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR     s    c	      
   C   sj   | j  ƒ  }	 g  }
 xQ | D]I } | j |	 | ƒ } | j | | | | | | | | ƒ } |
 j | ƒ q W|
 S(   N(   t   get_legend_handler_mapt   get_legend_handlerR    Rˆ   (   R   R   R   R   R   R   R   R   R(   t   handler_mapR$   t   handle1t   handlert   _a_list(    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR       s    	(   R)   R*   R+   R   R    (    (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyR§     s   	(   R+   t   numpyR3   t   matplotlib.linesR    t   matplotlib.patchesR   t   matplotlib.collectionst   collectionsR„   R   t   objectR   R,   R8   R?   RQ   RW   Rb   Rv   Rx   Ry   R—   R§   (    (    (    sS   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/legend_handler.pyt   <module>   s"   	Q%!Hp@