ó
ÄCõRc           @  s�   d  Z  d d l m Z d d l m Z m Z d d l Z d d d „  ƒ  YZ d d d „  ƒ  YZ	 d	 e
 f d
 „  ƒ  YZ e ƒ  Z d S(   sQ  
The classes here provide support for using custom classes with
matplotlib, eg those that do not expose the array interface but know
how to converter themselves to arrays.  It also supoprts classes with
units and units conversion.  Use cases include converters for custom
objects, eg a list of datetime objects, as well as for objects that
are unit aware.  We don't assume any particular units implementation,
rather a units implementation must provide a ConversionInterface, and
the register with the Registry converter dictionary.  For example,
here is a complete implementation which supports plotting with native
datetime objects::


    import matplotlib.units as units
    import matplotlib.dates as dates
    import matplotlib.ticker as ticker
    import datetime

    class DateConverter(units.ConversionInterface):

        @staticmethod
        def convert(value, unit, axis):
            'convert value to a scalar or array'
            return dates.date2num(value)

        @staticmethod
        def axisinfo(unit, axis):
            'return major and minor tick locators and formatters'
            if unit!='date': return None
            majloc = dates.AutoDateLocator()
            majfmt = dates.AutoDateFormatter(majloc)
            return AxisInfo(majloc=majloc,
                            majfmt=majfmt,
                            label='date')

        @staticmethod
        def default_units(x, axis):
            'return the default unit for x or None'
            return 'date'

    # finally we register our object type with a converter
    units.registry[datetime.date] = DateConverter()

iÿÿÿÿ(   t   print_function(   t   iterablet
   is_numlikeNt   AxisInfoc           B  s)   e  Z d  Z d d d d d d d „ Z RS(   sY   information to support default axis labeling and tick labeling, and
       default limitsc         C  s:   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ d S(   sW  
        majloc and minloc: TickLocators for the major and minor ticks
        majfmt and minfmt: TickFormatters for the major and minor ticks
        label: the default axis label
        default_limits: the default min, max of the axis if no data is present
        If any of the above are None, the axis will simply use the default
        N(   t   majloct   minloct   majfmtt   minfmtt   labelt   default_limits(   t   selfR   R   R   R   R   R	   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/units.pyt   __init__5   s    
					N(   t   __name__t
   __module__t   __doc__t   NoneR   (    (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/units.pyR   2   s   	t   ConversionInterfacec           B  sJ   e  Z d  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z RS(   s‚   
    The minimal interface for a converter to take custom instances (or
    sequences) and convert them to values mpl can use
    c         C  s   d S(   sC   return an units.AxisInfo instance for axis with the specified unitsN(   R   (   t   unitt   axis(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/units.pyt   axisinfoL   s    c         C  s   d S(   s8   return the default unit for x or None for the given axisN(   R   (   t   xR   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/units.pyt   default_unitsQ   s    c         C  s   |  S(   sÙ   
        convert obj using unit for the specified axis.  If obj is a sequence,
        return the converted sequence.  The ouput must be a sequence of scalars
        that can be used by the numpy array layer
        (    (   t   objR   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/units.pyt   convertV   s    c         C  s5   t  |  ƒ r' x" |  D] } t | ƒ SWn
 t |  ƒ Sd S(   s®  
        The matplotlib datalim, autoscaling, locators etc work with
        scalars which are the units converted to floats given the
        current unit.  The converter may be passed these floats, or
        arrays of them, even when units are set.  Derived conversion
        interfaces may opt to pass plain-ol unitless numbers through
        the conversion interface and this is a helper function for
        them.
        N(   R   R   (   R   t   thisx(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/units.pyR   _   s    (   R   R   R   t   staticmethodR   R   R   R   (    (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/units.pyR   G   s
   	t   Registryc           B  s    e  Z d  Z d „  Z d „  Z RS(   s2   
    register types with conversion interface
    c         C  s   t  j |  ƒ i  |  _ d  S(   N(   t   dictR   t   _cached(   R
   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/units.pyR   u   s    c         C  s2  t  |  ƒ s d Sd } t | d d ƒ } | d k	 rF |  j | ƒ } n  t | t j ƒ rÑ | j rÑ | j ƒ  } y9 t j	 | j
 ƒ s¥ |  j | t j | j
 ƒ ƒ } | SWqÑ t k
 rÍ |  j | d ƒ } | SXn  | d k r.t | ƒ r.xB | D]7 } | rð | t | d d ƒ k rð |  j | ƒ } | Sqð Wn  | S(   s3   get the converter interface instance for x, or Nonet	   __class__i    N(   t   lenR   t   getattrt   gett
   isinstancet   npt   ndarrayt   sizet   ravelt   allt   maskt   get_convertert   argmint   AttributeErrorR   (   R
   R   t	   convertert   classxt   xravelR   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/units.pyR(   y   s,    (   R   R   R   R   R(   (    (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/units.pyR   q   s   	(    (    (   R   t
   __future__R    t   matplotlib.cbookR   R   t   numpyR"   R   R   R   R   t   registry(    (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/units.pyt   <module>,   s   *3