
VÓW,  ã               @   s©   d  Z  d d l m Z m Z m Z m Z d d l m Z d d l m	 Z	 m
 Z
 d d l Z Gd d „  d e ƒ Z Gd d	 „  d	 e ƒ Z Gd
 d „  d e ƒ Z e ƒ  Z d S)aW  
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 converter themselves to arrays.  It also supoprts 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 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()

é    )Úabsolute_importÚdivisionÚprint_functionÚunicode_literals)Úsix)ÚiterableÚ
is_numlikeNc               @   s4   e  Z d  Z d Z d d d d d d d d „ Z d S)ÚAxisInfozYinformation to support default axis labeling and tick labeling, and
       default limitsNc             C   s:   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ d S)aW  
        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)ÚmajlocÚminlocÚmajfmtÚminfmtÚlabelÚdefault_limits)Úselfr
   r   r   r   r   r   © r   úK/s/python-3.5.2/amd64_ubu14/lib/python3.5/site-packages/matplotlib/units.pyÚ__init__9   s    
					zAxisInfo.__init__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r	   6   s   	r	   c               @   s^   e  Z d  Z d Z e d d „  ƒ Z e d d „  ƒ Z e d d „  ƒ Z e d d	 „  ƒ Z d
 S)ÚConversionInterfacez‚
    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)zCreturn an units.AxisInfo instance for axis with the specified unitsNr   )ÚunitÚaxisr   r   r   ÚaxisinfoP   s    zConversionInterface.axisinfoc             C   s   d S)z8return the default unit for x or None for the given axisNr   )Úxr   r   r   r   Údefault_unitsU   s    z!ConversionInterface.default_unitsc             C   s   |  S)zÙ
        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
        r   )Úobjr   r   r   r   r   ÚconvertZ   s    zConversionInterface.convertc             C   s5   t  |  ƒ r' x" |  D] } t | ƒ SWn
 t |  ƒ Sd S)a®  
        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   Úthisxr   r   r   r   c   s    zConversionInterface.is_numlikeN)	r   r   r   r   Ústaticmethodr   r   r   r   r   r   r   r   r   K   s
   	r   c               @   s.   e  Z d  Z d Z d d „  Z d d „  Z d S)ÚRegistryz2
    register types with conversion interface
    c             C   s   t  j |  ƒ i  |  _ d  S)N)Údictr   Ú_cached)r   r   r   r   r   y   s    zRegistry.__init__c             C   sX  t  |  ƒ s d Sd } t | d d ƒ } | d k	 rC |  j | ƒ } t | t j ƒ rú | j rú | j ƒ  } y9 t j | j	 ƒ s¢ |  j
 | t j | j	 ƒ ƒ } | SWnT t k
 rù | d } t | t j ƒ sâ | j | j k rñ |  j
 | ƒ } | SYn X| d k rTt | ƒ rTx? | D]7 } | r| t | d d ƒ k r|  j
 | ƒ } | SqW| S)z3get the converter interface instance for x, or NoneNÚ	__class__r   )ÚlenÚgetattrÚgetÚ
isinstanceÚnpÚndarrayÚsizeÚravelÚallÚmaskÚget_converterÚargminÚAttributeErrorÚshaper   )r   r   Ú	converterZclassxZxravelZ	next_itemr    r   r   r   r0   }   s2    
	zRegistry.get_converterN)r   r   r   r   r   r0   r   r   r   r   r"   u   s   r"   )r   Ú
__future__r   r   r   r   Zmatplotlib.externalsr   Zmatplotlib.cbookr   r   Únumpyr*   Úobjectr	   r   r#   r"   Úregistryr   r   r   r   Ú<module>,   s   "*9