B
    Afxa	                 @   sP   d Z ddlZddlmZmZ G dd dejjZG dd dejj	Z
d	d
 ZdS )a  
    pint.matplotlib
    ~~~~~~~~~~~~~~~

    Functions and classes related to working with Matplotlib's support
    for plotting with units.

    :copyright: 2017 by Pint Authors, see AUTHORS for more details.
    :license: BSD, see LICENSE for more details.
    N   )iterablesizedc                   s    e Zd ZdZ fddZ  ZS )PintAxisInfoz:Support default axis and tick labeling and default limits.c                s   t  jd|d dS )z6Set the default label to the pretty-print of the unit.z{:P})ZlabelN)super__init__format)selfunits)	__class__ .lib/python3.7/site-packages/pint/matplotlib.pyr      s    zPintAxisInfo.__init__)__name__
__module____qualname____doc__r   __classcell__r   r   )r   r   r      s   r   c                   sH   e Zd ZdZ fddZdd Zdd Zedd	 Zed
d Z	  Z
S )PintConverterzIImplement support for pint within matplotlib's unit conversion framework.c                s   t    || _d S )N)r   r   _reg)r	   registry)r   r   r   r      s    
zPintConverter.__init__c                s0   t |r fdd|D S | S dS )z4Convert :`Quantity` instances for matplotlib to use.c                s   g | ]} | qS r   )_convert_value).0v)axisr	   unitr   r   
<listcomp>#   s    z)PintConverter.convert.<locals>.<listcomp>N)r   r   )r	   valuer   r   r   )r   r	   r   r   convert    s    zPintConverter.convertc             C   s4   t |dr||jS | j|| |jS dS )zDHandle converting using attached unit or falling back to axis units.r
   N)hasattrtoZ	magnituder   QuantityZ	get_units)r	   r   r   r   r   r   r   r   '   s    
zPintConverter._convert_valuec             C   s   t | S )z1Return axis information for this particular unit.)r   )r   r   r   r   r   axisinfo.   s    zPintConverter.axisinfoc             C   s,   t | r t| r t| d ddS t| ddS )zGGet the default unit to use for the given combination of unit and axis.r   r
   N)r   r   getattr)xr   r   r   r   default_units4   s    zPintConverter.default_units)r   r   r   r   r   r   r   staticmethodr!   r$   r   r   r   )r   r   r      s   r   c             C   s@   t jdk rtd|r*t| t jj| j< nt jj| jd dS )a  Set up matplotlib's unit support to handle units from a registry.

    Parameters
    ----------
    registry : pint.UnitRegistry
        The registry that will be used.
    enable : bool
        Whether support should be enabled or disabled.

    Returns
    -------

    z2.0z-Matplotlib >= 2.0 required to work with pint.N)
matplotlib__version__RuntimeErrorr   r
   r   r    pop)r   enabler   r   r   setup_matplotlib_handlers<   s
    
r+   )r   Zmatplotlib.unitsr&   utilr   r   r
   ZAxisInfor   ZConversionInterfacer   r+   r   r   r   r   <module>
   s
   #