σ
 m[c           @` sv  d  Z  d d l m Z m Z m Z m Z d d l m Z d d l Z d d l	 Z	 d d l
 Z d d l j Z d d l j Z d d l m Z e e e	 j e e	 j e j e j f   Z d e j f d     YZ d e j f d	     YZ d
 e j f d     YZ d e  f d     YZ! e   e j" e# <e   e j" e j <e   e j" e	 j <e   e j" e <e   e j" e j <d S(   uΘ  
Module that allows plotting of string "category" data.  i.e.
``plot(['d', 'f', 'a'],[1, 2, 3])`` will plot three points with x-axis
values of 'd', 'f', 'a'.

See :doc:`/gallery/lines_bars_and_markers/categorical_variables` for an
example.

The module uses Matplotlib's `matplotlib.units` mechanism to convert from
strings to integers, provides a tick locator and formatter, and the
class:`.UnitData` that creates and stores the string-to-integer mapping.
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literals(   t   OrderedDictN(   t   LooseVersiont   StrCategoryConverterc           B` s5   e  Z e d     Z e d    Z e d    Z RS(   c         C` s   t  j t  j |  d t  } t d   | D  rG t  j | d t S| j |  t  j | j	 j
 d t g } | |  } | S(   u)  Converts strings in value to floats using
        mapping information store in the  unit object

        Parameters
        ----------
        value : string or iterable
            value or list of values to be converted
        unit : :class:`.UnitData`
           object string unit information for value
        axis : :class:`~matplotlib.Axis.axis`
            axis on which the converted value is plotted

        Returns
        -------
        mapped_ value : float or ndarray[float]

        .. note:: axis is not used in this function
        t   dtypec         s` s1   |  ]' } t  j j |  o( t | t  Vq d  S(   N(   t   unitst   ConversionInterfacet
   is_numliket
   isinstancet   VALID_TYPES(   t   .0t   v(    (    s2   lib/python2.7/site-packages/matplotlib/category.pys	   <genexpr><   s   t   otypes(   t   npt
   atleast_1dt   arrayt   objectt   allt   asarrayt   floatt   updatet	   vectorizet   _mappingt   __getitem__(   t   valuet   unitt   axist   valuest   str2idxt   mapped_value(    (    s2   lib/python2.7/site-packages/matplotlib/category.pyt   convert$   s    	c         C` s4   t  |  j  } t |  j  } t j d | d |  S(   uΆ  Sets the default axis ticks and labels

        Parameters
        ---------
        unit : :class:`.UnitData`
            object string unit information for value
        axis : :class:`~matplotlib.Axis.axis`
            axis for which information is being set

        Returns
        -------
        :class:~matplotlib.units.AxisInfo~
            Information to support default tick labeling

        .. note: axis is not used
        t   majloct   majfmt(   t   StrCategoryLocatorR   t   StrCategoryFormatterR   t   AxisInfo(   R   R   R"   R#   (    (    s2   lib/python2.7/site-packages/matplotlib/category.pyt   axisinfoI   s    c         C` s<   | j  d k r% | j t |    n | j  j |   | j  S(   uc   Sets and updates the :class:`~matplotlib.Axis.axis~ units

        Parameters
        ----------
        data : string or iterable of strings
        axis : :class:`~matplotlib.Axis.axis`
            axis on which the data is plotted

        Returns
        -------
        class:~.UnitData~
            object storing string to integer mapping
        N(   R   t   Nonet	   set_unitst   UnitDataR   (   t   dataR   (    (    s2   lib/python2.7/site-packages/matplotlib/category.pyt   default_unitsa   s    (   t   __name__t
   __module__t   staticmethodR!   R'   R,   (    (    (    s2   lib/python2.7/site-packages/matplotlib/category.pyR   #   s   %R$   c           B` s)   e  Z d  Z d   Z d   Z d   Z RS(   u0   tick at every integer mapping of the string datac         C` s   | |  _  d S(   u{   
        Parameters
        -----------
        units_mapping : Dict[str, int]
             string:integer mapping
        N(   t   _units(   t   selft   units_mapping(    (    s2   lib/python2.7/site-packages/matplotlib/category.pyt   __init__{   s    c         C` s   t  |  j j    S(   N(   t   listR0   R   (   R1   (    (    s2   lib/python2.7/site-packages/matplotlib/category.pyt   __call__   s    c         C` s   |    S(   N(    (   R1   t   vmint   vmax(    (    s2   lib/python2.7/site-packages/matplotlib/category.pyt   tick_values   s    (   R-   R.   t   __doc__R3   R5   R8   (    (    (    s2   lib/python2.7/site-packages/matplotlib/category.pyR$   y   s   			R%   c           B` s2   e  Z d  Z d   Z d d  Z e d    Z RS(   u/   String representation of the data at every tickc         C` s   | |  _  d S(   uy   
        Parameters
        ----------
        units_mapping : Dict[Str, int]
            string:integer mapping
        N(   R0   (   R1   R2   (    (    s2   lib/python2.7/site-packages/matplotlib/category.pyR3      s    c         C` sH   | d  k r d Sd   |  j j   D } | j t t j |   d  S(   Nu    c         S` s(   i  |  ] \ } } t  j |  |  q S(    (   R%   t   _text(   R   t   kR   (    (    s2   lib/python2.7/site-packages/matplotlib/category.pys
   <dictcomp>   s   	(   R(   R0   t   itemst   gett   intR   t   round(   R1   t   xt   post	   r_mapping(    (    s2   lib/python2.7/site-packages/matplotlib/category.pyR5      s
    c         C` s΅   t  t j  t  d  k  rW t |  t j t j f  rW |  j d d  j d  }  qW n  t |  t j	 t j
 f  r |  j d d  }  n* t |  t j t j f  s± t |   }  n  |  S(   u=   Converts text values into `utf-8` or `ascii` strings
        u   1.7.0u   utf-8u   ignoret   encoding(   R   R   t   __version__R   t   sixt	   text_typet   unicodet   encodet   decodet   bytes_t   binary_typet   str_t   string_typest   str(   R   (    (    s2   lib/python2.7/site-packages/matplotlib/category.pyR:      s    !N(   R-   R.   R9   R3   R(   R5   R/   R:   (    (    (    s2   lib/python2.7/site-packages/matplotlib/category.pyR%      s   		R*   c           B` s   e  Z d d   Z d   Z RS(   c         C` sA   t    |  _ t j d d  |  _ | d k	 r= |  j |  n  d S(   u«   Create mapping between unique categorical values
        and integer identifiers
        ----------
        data: iterable
              sequence of string values
        t   starti    N(   R   R   t	   itertoolst   countt   _counterR(   R   (   R1   R+   (    (    s2   lib/python2.7/site-packages/matplotlib/category.pyR3   ¬   s    c         C` s   t  j t  j | d t  } xi t j |  D]X } t | t  s^ t d j	 d |    n  | |  j
 k r. t |  j  |  j
 | <q. q. Wd S(   u  Maps new values to integer identifiers.

        Paramters
        ---------
        data: iterable
              sequence of string values

        Raises
        ------
        TypeError
              If the value in data is not a string, unicode, bytes type
        R   u   {val!r} is not a stringt   valN(   R   R   R   R   R   t   fromkeysR   R   t	   TypeErrort   formatR   t   nextRR   (   R1   R+   RS   (    (    s2   lib/python2.7/site-packages/matplotlib/category.pyR   Έ   s    N(   R-   R.   R(   R3   R   (    (    (    s2   lib/python2.7/site-packages/matplotlib/category.pyR*   «   s   ($   R9   t
   __future__R    R   R   R   t   collectionsR   RP   RE   t   numpyR   t   matplotlib.unitsR   t   matplotlib.tickert   tickert   distutils.versionR   t   tuplet   setRM   t   bytesRF   RL   RJ   R   R	   R   t   LocatorR$   t	   FormatterR%   R   R*   t   registryRN   (    (    (    s2   lib/python2.7/site-packages/matplotlib/category.pyt   <module>   s&   ""V $