ó
 m[c           @` sp  d  Z  d d l m Z m Z m Z m Z d d l Z d d l Z d d l m	 Z	 d d l
 Z d d l j Z d d l j Z d d l m Z d d l m Z i  Z d „  Z d „  Z d	 „  Z d
 „  Z e j d Z e j d „  e j e ƒ Dƒ ƒ x! e D] Z e e e ƒ e e <qø We j e ƒ e ƒ  j e ƒ d d d d d „ Z! d d d „ Z" d e# f d „  ƒ  YZ$ d S(   uð   
Builtin colormaps, colormap handling utilities, and the `ScalarMappable` mixin.

See :doc:`/gallery/color/colormap_reference` for a list of builtin colormaps.
See :doc:`/tutorials/colors/colormaps` for an in-depth discussion of colormaps.
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   ma(   t   datad(   t   cmapsc         ` s   ‡  f d †  } | S(   Nc         ` s   ˆ  d |  ƒ S(   Ni   (    (   t   x(   t   f(    s,   lib/python2.7/site-packages/matplotlib/cm.pyt	   freversed   s    (    (   R   R	   (    (   R   s,   lib/python2.7/site-packages/matplotlib/cm.pyt	   _reverser   s    c         C` s„   i  } xw t  j |  ƒ D]f \ } } t | ƒ r= t | ƒ } n5 g  t | ƒ D]" \ } } } d | | | f ^ qJ } | | | <q W| S(   u:   Can only handle specification *data* in dictionary format.g      ð?(   t   sixt	   iteritemst   callableR
   t   reversed(   t   datat   data_rt   keyt   valt   valnewR   t   y0t   y1(    (    s,   lib/python2.7/site-packages/matplotlib/cm.pyt   revcmap"   s    5c         C` sš   d |  k r( i |  d d d d … d 6Sd |  k r> t  |  ƒ St t |  ƒ ƒ } t | d ƒ d k r’ g  | D] \ } } d | | f ^ qm } n  | Sd S(   uR   Reverses cmap specification *spec*, can handle both dict and tuple
    type specs.u   listedNiÿÿÿÿu   redi    i   g      ð?(   R   t   listR   t   len(   t   spect   revspect   at   b(    (    s,   lib/python2.7/site-packages/matplotlib/cm.pyt   _reverse_cmap_spec3   s    
,c         C` sc   t  |  } d | k r) t j |  | | ƒ Sd | k rI t j | d |  ƒ St j j |  | | ƒ Sd S(   uM   Generates the requested cmap from its *name*.  The lut size is
    *lutsize*.u   redu   listedN(   R   t   colorst   LinearSegmentedColormapt   ListedColormapt	   from_list(   t   namet   lutsizeR   (    (    s,   lib/python2.7/site-packages/matplotlib/cm.pyt   _generate_cmapC   s    
u	   image.lutc         C` s)   i  |  ] \ } } t  | ƒ | d  “ q S(   u   _r(   R   (   t   .0t   cmapnameR   (    (    s,   lib/python2.7/site-packages/matplotlib/cm.pys
   <dictcomp>U   s   	c         C` s¼   |  d k r< y | j }  Wq< t k
 r8 t d ƒ ‚ q< Xn  t |  t j ƒ s] t d ƒ ‚ n  t | t j ƒ r} | t	 |  <d S| d k r™ t
 j d } n  t j |  | | ƒ } | t	 |  <d S(   uj  
    Add a colormap to the set recognized by :func:`get_cmap`.

    It can be used in two ways::

        register_cmap(name='swirly', cmap=swirly_cmap)

        register_cmap(name='choppy', data=choppydata, lut=128)

    In the first case, *cmap* must be a :class:`matplotlib.colors.Colormap`
    instance.  The *name* is optional; if absent, the name will
    be the :attr:`~matplotlib.colors.Colormap.name` attribute of the *cmap*.

    In the second case, the three arguments are passed to
    the :class:`~matplotlib.colors.LinearSegmentedColormap` initializer,
    and the resulting colormap is registered.

    u+   Arguments must include a name or a Colormapu   Colormap name must be a stringNu	   image.lut(   t   NoneR"   t   AttributeErrort
   ValueErrort
   isinstanceR   t   string_typesR   t   Colormapt   cmap_dt   mplt   rcParamsR   (   R"   t   cmapR   t   lut(    (    s,   lib/python2.7/site-packages/matplotlib/cm.pyt   register_cmape   s    
c         C` s   |  d k r t j d }  n  t |  t j ƒ r2 |  S|  t k rf | d k rR t |  St |  j | ƒ Sn% t d |  d j	 t
 t ƒ ƒ f ƒ ‚ d S(   u¨  
    Get a colormap instance, defaulting to rc values if *name* is None.

    Colormaps added with :func:`register_cmap` take precedence over
    built-in colormaps.

    If *name* is a :class:`matplotlib.colors.Colormap` instance, it will be
    returned.

    If *lut* is not None it must be an integer giving the number of
    entries desired in the lookup table, and *name* must be a standard
    mpl colormap name.
    u
   image.cmapu6   Colormap %s is not recognized. Possible values are: %su   , N(   R'   R.   R/   R*   R   R,   R-   t	   _resampleR)   t   joint   sorted(   R"   R1   (    (    s,   lib/python2.7/site-packages/matplotlib/cm.pyt   get_cmapŒ   s    t   ScalarMappablec           B` s¡   e  Z d  Z d d d „ Z d e e d „ Z d „  Z d „  Z	 d „  Z
 d „  Z d d d „ Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z RS(   u¹   
    This is a mixin class to support scalar data to RGBA mapping.
    The ScalarMappable makes use of data normalization before returning
    RGBA colors from the given colormap.

    c         C` s€   t  j ƒ  |  _ | d k r' t ƒ  } n  | d k rB t j ƒ  } n  d |  _ | |  _ t | ƒ |  _	 d |  _
 i t d 6|  _ d S(   uú  

        Parameters
        ----------
        norm : :class:`matplotlib.colors.Normalize` instance
            The normalizing object which scales data, typically into the
            interval ``[0, 1]``.
            If *None*, *norm* defaults to a *colors.Normalize* object which
            initializes its scaling based on the first data processed.
        cmap : str or :class:`~matplotlib.colors.Colormap` instance
            The colormap used to map normalized data values to RGBA colors.
        u   arrayN(   t   cbookt   CallbackRegistryt   callbacksSMR'   R6   R   t	   Normalizet   _At   normR0   t   colorbart   Falset   update_dict(   t   selfR=   R0   (    (    s,   lib/python2.7/site-packages/matplotlib/cm.pyt   __init__²   s    			c   	      C` s  yÁ| j  d k rÀ| j d d k rà | d k r: d } n  | j t j k rb t j | d ƒ } n  | j d  \ } } t j d | | d f d | j ƒ } | | d d … d d … d d … f <| | d d … d d … d f <n( | j d d k rü | } n t d	 ƒ ‚ | j j d
 k ru| rS| j	 ƒ  d k sD| j
 ƒ  d k  rSt d ƒ ‚ n  | r¼| d j t j ƒ } q¼nG | j t j k r©| s¼| j t j ƒ d } q¼n t d | j ƒ ‚ | SWn t k
 rÔn Xt j | ƒ } | rü|  j | ƒ } n  |  j | d | d | ƒ} | S(   u­  
        Return a normalized rgba array corresponding to *x*.

        In the normal case, *x* is a 1-D or 2-D sequence of scalars, and
        the corresponding ndarray of rgba values will be returned,
        based on the norm and colormap set for this ScalarMappable.

        There is one special case, for handling images that are already
        rgb or rgba, such as might have been read from an image file.
        If *x* is an ndarray with 3 dimensions,
        and the last dimension is either 3 or 4, then it will be
        treated as an rgb or rgba array, and no mapping will be done.
        The array can be uint8, or it can be floating point with
        values in the 0-1 range; otherwise a ValueError will be raised.
        If it is a masked array, the mask will be ignored.
        If the last dimension is 3, the *alpha* kwarg (defaulting to 1)
        will be used to fill in the transparency.  If the last dimension
        is 4, the *alpha* kwarg is ignored; it does not
        replace the pre-existing alpha.  A ValueError will be raised
        if the third dimension is other than 3 or 4.

        In either case, if *bytes* is *False* (default), the rgba
        array will be floats in the 0-1 range; if it is *True*,
        the returned rgba array will be uint8 in the 0 to 255 range.

        If norm is False, no normalization of the input data is
        performed, and it is assumed to be in the range (0-1).

        i   i   i   iÿ   t   shapei   t   dtypeNu   third dimension must be 3 or 4u   fi    u:   Floating point image RGB values must be in the 0..1 range.u9   Image RGB array must be uint8 or floating point; found %st   alphat   bytes(   t   ndimRC   R'   RD   t   npt   uint8t   emptyR)   t   kindt   maxt   mint   astypet   float32R(   R   t   asarrayR=   R0   (	   RA   R   RE   RF   R=   t   mt   nt   xxt   rgba(    (    s,   lib/python2.7/site-packages/matplotlib/cm.pyt   to_rgbaÐ   s@    	$%"	*c         C` s   | |  _  t |  j d <d S(   uŠ   Set the image array from numpy array *A*.

        .. ACCEPTS: ndarray

        Parameters
        ----------
        A : ndarray
        u   arrayN(   R<   t   TrueR@   (   RA   t   A(    (    s,   lib/python2.7/site-packages/matplotlib/cm.pyt	   set_array  s    		c         C` s   |  j  S(   u   Return the array(   R<   (   RA   (    (    s,   lib/python2.7/site-packages/matplotlib/cm.pyt	   get_array"  s    c         C` s   |  j  S(   u   return the colormap(   R0   (   RA   (    (    s,   lib/python2.7/site-packages/matplotlib/cm.pyR6   &  s    c         C` s   |  j  j |  j  j f S(   u9   return the min, max of the color limits for image scaling(   R=   t   vmint   vmax(   RA   (    (    s,   lib/python2.7/site-packages/matplotlib/cm.pyt   get_clim*  s    c         C` s   | d k r9 y | \ } } Wq9 t t f k
 r5 q9 Xn  | d k	 r] t j | ƒ |  j _ n  | d k	 r t j | ƒ |  j _ n  |  j ƒ  d S(   u&  
        set the norm limits for image scaling; if *vmin* is a length2
        sequence, interpret it as ``(vmin, vmax)`` which is used to
        support setp

        ACCEPTS: a length 2 sequence of floats; may be overridden in methods
        that have ``vmin`` and ``vmax`` kwargs.
        N(	   R'   t	   TypeErrorR)   R   t   _sanitize_extremaR=   RZ   R[   t   changed(   RA   RZ   R[   (    (    s,   lib/python2.7/site-packages/matplotlib/cm.pyt   set_clim.  s    	c         C` s#   t  | ƒ } | |  _ |  j ƒ  d S(   un   
        set the colormap for luminance data

        ACCEPTS: a colormap or registered colormap name
        N(   R6   R0   R_   (   RA   R0   (    (    s,   lib/python2.7/site-packages/matplotlib/cm.pyt   set_cmapB  s    	c         C` s2   | d k r t j ƒ  } n  | |  _ |  j ƒ  d S(   u   Set the normalization instance.

        .. ACCEPTS: `.Normalize`

        Parameters
        ----------
        norm : `.Normalize`
        N(   R'   R   R;   R=   R_   (   RA   R=   (    (    s,   lib/python2.7/site-packages/matplotlib/cm.pyt   set_normL  s    		c         C` s?   |  j  d k r t d ƒ ‚ n  |  j j |  j  ƒ |  j ƒ  d S(   ub   
        Autoscale the scalar limits on the norm instance using the
        current array
        u%   You must first set_array for mappableN(   R<   R'   R]   R=   t	   autoscaleR_   (   RA   (    (    s,   lib/python2.7/site-packages/matplotlib/cm.pyRc   Z  s    c         C` s?   |  j  d k r t d ƒ ‚ n  |  j j |  j  ƒ |  j ƒ  d S(   u†   
        Autoscale the scalar limits on the norm instance using the
        current array, changing only limits that are None
        u%   You must first set_array for mappableN(   R<   R'   R]   R=   t   autoscale_NoneR_   (   RA   (    (    s,   lib/python2.7/site-packages/matplotlib/cm.pyRd   d  s    c         C` s   t  |  j | <d S(   uz   
        Add an entry to a dictionary of boolean flags
        that are set to True when the mappable is changed.
        N(   R?   R@   (   RA   t   checker(    (    s,   lib/python2.7/site-packages/matplotlib/cm.pyt   add_checkern  s    c         C` s"   |  j  | r t |  j  | <t St S(   uf   
        If mappable has changed since the last check,
        return True; else return False
        (   R@   R?   RV   (   RA   Re   (    (    s,   lib/python2.7/site-packages/matplotlib/cm.pyt   check_updateu  s    c         C` sA   |  j  j d |  ƒ x |  j D] } t |  j | <q Wt |  _ d S(   uƒ   
        Call this whenever the mappable is changed to notify all the
        callbackSM listeners to the 'changed' signal
        u   changedN(   R:   t   processR@   RV   t   stale(   RA   R   (    (    s,   lib/python2.7/site-packages/matplotlib/cm.pyR_     s    N(   t   __name__t
   __module__t   __doc__R'   RB   R?   RV   RU   RX   RY   R6   R\   R`   Ra   Rb   Rc   Rd   Rf   Rg   R_   (    (    (    s,   lib/python2.7/site-packages/matplotlib/cm.pyR7   «   s   F					
		
	
		
(%   Rl   t
   __future__R    R   R   R   R   t   numpyRH   R   t
   matplotlibR.   t   matplotlib.colorsR   t   matplotlib.cbookR8   t   matplotlib._cmR   t   matplotlib._cm_listedR   t   cmaps_listedR-   R
   R   R   R$   R/   t   LUTSIZEt   updateR   R&   t   localsR'   R2   R6   t   objectR7   (    (    (    s,   lib/python2.7/site-packages/matplotlib/cm.pyt   <module>   s0   "				'