ó
±éRc           @  s~  d  Z  d d l 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 e ƒ  Z d „  Z d „  Z d	 „  Z d
 „  Z e	 j d Z e j ƒ  Z x2 e D]* Z e e Z e e ƒ Z e e e d <qÛ Wx' e j ƒ  D] Z e e e ƒ e e <qWe ƒ  j  e ƒ d d d d d „ Z" d d d „ Z# d d d „  ƒ  YZ$ d S(   s·   
This module provides a large set of colormaps, functions for
registering new colormaps and for getting a colormap by name,
and a mixin class for adding color mapping functionality.

iÿÿÿÿ(   t   print_functiont   divisionN(   t   ma(   t   datad(   t	   cubehelixc           s   ‡  f d †  } | S(   Nc           s   ˆ  d |  ƒ S(   Ni   (    (   t   x(   t   f(    sG   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/cm.pyt	   freversed   s    (    (   R   R   (    (   R   sG   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/cm.pyt	   _reverser   s    c         C  s�   i  } xt |  j  ƒ  D]f \ } } t | ƒ r: t | ƒ } n5 g  t | ƒ D]" \ } } } d | | | f ^ qG } | | | <q W| S(   s:   Can only handle specification *data* in dictionary format.g      ð?(   t	   iteritemst   callableR   t   reversed(   t   datat   data_rt   keyt   valt   valnewR   t   y0t   y1(    (    sG   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/cm.pyt   revcmap   s    5c         C  sr   d |  k r t  |  ƒ St t |  ƒ ƒ } t | d ƒ d k rj g  | D] \ } } d | | f ^ qE } n  | Sd S(   sR   Reverses cmap specification *spec*, can handle both dict and tuple
    type specs.t   redi    i   g      ð?N(   R   t   listR   t   len(   t   spect   revspect   at   b(    (    sG   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/cm.pyt   _reverse_cmap_spec0   s    
,c         C  sC   t  |  } d | k r) t j |  | | ƒ St j j |  | | ƒ Sd S(   sS   Generates the requested cmap from it's name *name*.  The lut size is
    *lutsize*.R   N(   R   t   colorst   LinearSegmentedColormapt	   from_list(   t   namet   lutsizeR   (    (    sG   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/cm.pyt   _generate_cmap=   s    
s	   image.lutt   _rc         C  s¹   |  d k r< y | j }  Wq< t k
 r8 t d ƒ ‚ q< Xn  t j |  ƒ sZ t d ƒ ‚ n  t | t j ƒ rz | t	 |  <d S| d k r– t
 j d } n  t j |  | | ƒ } | t	 |  <d S(   sj  
    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.

    s+   Arguments must include a name or a Colormaps   Colormap name must be a stringNs	   image.lut(   t   NoneR   t   AttributeErrort
   ValueErrort   cbookt   is_string_liket
   isinstanceR   t   Colormapt   cmap_dt   mplt   rcParamsR   (   R   t   cmapR   t   lut(    (    sG   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/cm.pyt   register_cmap_   s    
c         C  s‚   |  d k r t j d }  n  t |  t j ƒ r2 |  S|  t k rn | d k rR t |  S|  t k rn t |  | ƒ Sn  t	 d |  ƒ ‚ d S(   sÜ  
    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 with a corresponding data dictionary
    in *datad*.
    s
   image.cmaps   Colormap %s is not recognizedN(
   R#   R+   R,   R(   R   R)   R*   R   R!   R%   (   R   R.   (    (    sG   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/cm.pyt   get_cmap†   s    t   ScalarMappablec           B  s¼   e  Z d  Z d d d „ Z e j d d d ƒd „  ƒ Z d 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(   s¹   
    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(   sh  

        Parameters
        ----------
        norm : :class:`matplotlib.colors.Normalize` instance
            The normalizing object which scales data, typically into the
            interval ``[0, 1]``.
        cmap : str or :class:`~matplotlib.colors.Colormap` instance
            The colormap used to map normalized data values to RGBA colors.

        t   arrayN(   R&   t   CallbackRegistryt   callbacksSMR#   R0   R   t	   Normalizet   _At   normR-   t   colorbart   Falset   update_dict(   t   selfR7   R-   (    (    sG   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/cm.pyt   __init__«   s    			s   1.3t   alternatives   the colorbar attributec         C  s   | |  _  d S(   s<   set the colorbar and axes instances associated with mappableN(   R8   (   R;   t   imt   ax(    (    sG   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/cm.pyt   set_colorbarÈ   s    c         C  s¾  ym| j  d k rl| 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	 ƒ ‚ | r9| j t j k r9| d j t j ƒ } n  | rh| j t j k rh| j t	 ƒ d } n  | SWn t
 k
 r€n Xt j | ƒ } |  j | ƒ } |  j | d
 | d | ƒ} | S(   sx  
        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.
        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.

        Note: this method assumes the input is well-behaved; it does
        not check for anomalies such as *x* being a masked rgba
        array, or being an integer type other than uint8, or being
        a floating point rgba array with values outside the 0-1 range.
        i   i   i   iÿ   t   shapei   t   dtypeNs   third dimension must be 3 or 4t   alphat   bytes(   t   ndimRA   R#   RB   t   npt   uint8t   emptyR%   t   astypet   floatR$   R   t   asarrayR7   R-   (   R;   R   RC   RD   t   mt   nt   xx(    (    sG   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/cm.pyt   to_rgbaÍ   s2    	$%"	c         C  s   | |  _  t |  j d <d S(   s(   Set the image array from numpy array *A*R2   N(   R6   t   TrueR:   (   R;   t   A(    (    sG   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/cm.pyt	   set_array  s    	c         C  s   |  j  S(   s   Return the array(   R6   (   R;   (    (    sG   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/cm.pyt	   get_array  s    c         C  s   |  j  S(   s   return the colormap(   R-   (   R;   (    (    sG   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/cm.pyR0     s    c         C  s   |  j  j |  j  j f S(   s9   return the min, max of the color limits for image scaling(   R7   t   vmint   vmax(   R;   (    (    sG   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/cm.pyt   get_clim  s    c         C  sŒ   | d k	 rH | d k rH t j | ƒ rH t | ƒ d k rH | \ } } n  | d k	 rc | |  j _ n  | d k	 r~ | |  j _ n  |  j ƒ  d S(   sØ   
        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
        i   N(   R#   R&   t   iterableR   R7   RT   RU   t   changed(   R;   RT   RU   (    (    sG   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/cm.pyt   set_clim  s    !c         C  s#   t  | ƒ } | |  _ |  j ƒ  d S(   sn   
        set the colormap for luminance data

        ACCEPTS: a colormap or registered colormap name
        N(   R0   R-   RX   (   R;   R-   (    (    sG   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/cm.pyt   set_cmap+  s    	c         C  s2   | d k r t j ƒ  } n  | |  _ |  j ƒ  d S(   s   set the normalization instanceN(   R#   R   R5   R7   RX   (   R;   R7   (    (    sG   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/cm.pyt   set_norm5  s    	c         C  s?   |  j  d k r t d ƒ ‚ n  |  j j |  j  ƒ |  j ƒ  d S(   sb   
        Autoscale the scalar limits on the norm instance using the
        current array
        s%   You must first set_array for mappableN(   R6   R#   t	   TypeErrorR7   t	   autoscaleRX   (   R;   (    (    sG   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/cm.pyR]   <  s    c         C  s?   |  j  d k r t d ƒ ‚ n  |  j j |  j  ƒ |  j ƒ  d S(   s†   
        Autoscale the scalar limits on the norm instance using the
        current array, changing only limits that are None
        s%   You must first set_array for mappableN(   R6   R#   R\   R7   t   autoscale_NoneRX   (   R;   (    (    sG   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/cm.pyR^   F  s    c         C  s   t  |  j | <d S(   sz   
        Add an entry to a dictionary of boolean flags
        that are set to True when the mappable is changed.
        N(   R9   R:   (   R;   t   checker(    (    sG   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/cm.pyt   add_checkerP  s    c         C  s"   |  j  | r t |  j  | <t St S(   sf   
        If mappable has changed since the last check,
        return True; else return False
        (   R:   R9   RP   (   R;   R_   (    (    sG   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/cm.pyt   check_updateW  s    c         C  s8   |  j  j d |  ƒ x |  j D] } t |  j | <q Wd S(   sƒ   
        Call this whenever the mappable is changed to notify all the
        callbackSM listeners to the 'changed' signal
        RX   N(   R4   t   processR:   RP   (   R;   R   (    (    sG   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/cm.pyRX   a  s    N(   t   __name__t
   __module__t   __doc__R#   R<   R&   t
   deprecatedR@   R9   RO   RR   RS   R0   RV   RY   RZ   R[   R]   R^   R`   Ra   RX   (    (    (    sG   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/cm.pyR1   ¤   s    ;					
		
	
		
(    (%   Re   t
   __future__R    R   t   ost   numpyRF   R   t
   matplotlibR+   t   matplotlib.colorsR   t   matplotlib.cbookR&   t   matplotlib._cmR   R   t   dictR*   R   R   R   R!   R,   t   LUTSIZEt   keyst
   _cmapnamest   cmapnameR   t   spec_reversedt   iterkeyst   localst   updateR#   R/   R0   R1   (    (    (    sG   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/cm.pyt   <module>   s4   					
'