ó
 m[c           @` s«   d  Z  d d l m Z m Z m Z m Z d d l Z d d l m Z m	 Z	 m
 Z
 d d l Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ e ƒ  Z d S(   us  
The classes here provide support for using custom classes with
Matplotlib, e.g., those that do not expose the array interface but know
how to convert themselves to arrays.  It also supports classes with
units and units conversion.  Use cases include converters for custom
objects, e.g., 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 the register with the Registry
converter dictionary and a `ConversionInterface`.  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 a datetime 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 the Matplotlib units registry.
    units.registry[datetime.date] = DateConverter()

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   iterablet
   is_numliket   safe_first_elementt   AxisInfoc           B` s)   e  Z d  Z d d d d d d d „ Z RS(   u¶   
    Information to support default axis labeling, tick labeling, and
    default limits. An instance of this class must be returned by
    :meth:`ConversionInterface.axisinfo`.
    c         C` s:   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ d S(   u:  
        Parameters
        ----------
        majloc, minloc : Locator, optional
            Tick locators for the major and minor ticks.
        majfmt, minfmt : Formatter, optional
            Tick formatters for the major and minor ticks.
        label : str, optional
            The default axis label.
        default_limits : optional
            The default min and max limits of the axis if no data has
            been plotted.

        Notes
        -----
        If any of the above are ``None``, the axis will simply use the
        default value.
        N(   t   majloct   minloct   majfmtt   minfmtt   labelt   default_limits(   t   selfR   R	   R
   R   R   R   (    (    s/   lib/python2.7/site-packages/matplotlib/units.pyt   __init__;   s    					N(   t   __name__t
   __module__t   __doc__t   NoneR   (    (    (    s/   lib/python2.7/site-packages/matplotlib/units.pyR   5   s   	t   ConversionInterfacec           B` sJ   e  Z d  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z RS(   u‹   
    The minimal interface for a converter to take custom data types (or
    sequences) and convert them to values Matplotlib can use.
    c         C` s   d S(   ue   
        Return an `~units.AxisInfo` instance for the axis with the
        specified units.
        N(   R   (   t   unitt   axis(    (    s/   lib/python2.7/site-packages/matplotlib/units.pyt   axisinfo]   s    c         C` s   d S(   uQ   
        Return the default unit for *x* or ``None`` for the given axis.
        N(   R   (   t   xR   (    (    s/   lib/python2.7/site-packages/matplotlib/units.pyt   default_unitse   s    c         C` s   |  S(   ué   
        Convert *obj* using *unit* for the specified *axis*.
        If *obj* is a sequence, return the converted sequence.
        The output must be a sequence of scalars that can be used by the numpy
        array layer.
        (    (   t   objR   R   (    (    s/   lib/python2.7/site-packages/matplotlib/units.pyt   convertl   s    c         C` s5   t  |  ƒ r' x" |  D] } t | ƒ SWn
 t |  ƒ Sd S(   u  
        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.
        N(   R   R   (   R   t   thisx(    (    s/   lib/python2.7/site-packages/matplotlib/units.pyR   v   s    (   R   R   R   t   staticmethodR   R   R   R   (    (    (    s/   lib/python2.7/site-packages/matplotlib/units.pyR   X   s
   
t   Registryc           B` s    e  Z d  Z d „  Z d „  Z RS(   u>   
    A register that maps types to conversion interfaces.
    c         C` s   t  j |  ƒ i  |  _ d  S(   N(   t   dictR   t   _cached(   R   (    (    s/   lib/python2.7/site-packages/matplotlib/units.pyR   ‰   s    c         C` s”  t  |  ƒ s d Sd } t | d d ƒ } | d k	 rF |  j | ƒ } n  | d k rm t | d ƒ rm | j } n  t | t j ƒ r&| j	 r&| j
 ƒ  } y9 t j | j ƒ sÌ |  j | t j | j ƒ ƒ } | SWq&t k
 r"| d } t | t j ƒ s| j | j k r|  j | ƒ } n  | SXn  | d k ry t | ƒ } Wn t t f k
 r[qX| r| t | d d ƒ k r|  j | ƒ } | Sn  | S(   uŽ   
        Get the converter for data that has the same type as *x*. If no
        converters are registered for *x*, returns ``None``.
        u	   __class__u   valuesi    N(   t   lenR   t   getattrt   gett   hasattrt   valuest
   isinstancet   npt   ndarrayt   sizet   ravelt   allt   maskt   get_convertert   argmint   AttributeErrort   shapeR   t	   TypeErrort   StopIteration(   R   R   t	   convertert   classxt   xravelt	   next_itemR   (    (    s/   lib/python2.7/site-packages/matplotlib/units.pyR-      s<    
(   R   R   R   R   R-   (    (    (    s/   lib/python2.7/site-packages/matplotlib/units.pyR   …   s   	(   R   t
   __future__R    R   R   R   t   sixt   matplotlib.cbookR   R   R   t   numpyR'   t   objectR   R   R   R   t   registry(    (    (    s/   lib/python2.7/site-packages/matplotlib/units.pyt   <module>+   s   "#-C