a
    Sica                     @   s   d Z ddlmZ ddlmZ ddlZddlmZ ddlm	Z	m
Z
 G dd deZd	d
 ZG dd dZG dd dZG dd deZG dd deZe Ze ee< dS )aQ  
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 register with the Registry converter
dictionary and provide 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 units.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()
    )Decimal)NumberN)ma)_apicbookc                   @   s   e Zd ZdS )ConversionErrorN)__name__
__module____qualname__ r   r   L/var/www/html/django/DPS/env/lib/python3.9/site-packages/matplotlib/units.pyr   4   s   r   c                 C   sT   t | r:| D ](}|tju rqt|to2t|t   S nt| toNt| t S dS )zu
    Return whether *x* is of a type that Matplotlib natively supports or an
    array of objects of such types.
    N)npiterabler   masked
isinstancer   r   xthisxr   r   r   _is_natively_supported8   s    

r   c                   @   s   e Zd ZdZdddZdS )AxisInfoz
    Information to support default axis labeling, tick labeling, and limits.

    An instance of this class must be returned by
    `ConversionInterface.axisinfo`.
    Nc                 C   s(   || _ || _|| _|| _|| _|| _dS )a:  
        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)majlocminlocmajfmtminfmtlabeldefault_limits)selfr   r   r   r   r   r   r   r   r   __init__O   s    zAxisInfo.__init__)NNNNNN)r   r	   r
   __doc__r   r   r   r   r   r   H   s
      r   c                   @   sJ   e Zd ZdZedd Zedd Zedd Zee	dd	d
 Z
dS )ConversionInterfacez
    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 )z<Return an `.AxisInfo` for the axis with the specified units.Nr   )unitaxisr   r   r   axisinfor   s    zConversionInterface.axisinfoc                 C   s   dS )z?Return the default unit for *x* or ``None`` for the given axis.Nr   )r   r!   r   r   r   default_unitsw   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 output must
        be a sequence of scalars that can be used by the numpy array layer.
        r   )objr    r!   r   r   r   convert|   s    zConversionInterface.convertz3.5c                 C   s<   t | r.| D ]}|tju rqt|t  S n
t| tS d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.
        N)r   r   r   r   r   r   r   r   r   r   
is_numlike   s    	

zConversionInterface.is_numlikeN)r   r	   r
   r   staticmethodr"   r#   r%   r   
deprecatedr&   r   r   r   r   r   l   s   


	r   c                   @   s   e Zd ZdZedd ZdS )DecimalConverterz,Converter for decimal.Decimal data to float.c                 C   s>   t | trt| S t | tjr,tj| tdS tj| tdS dS )z
        Convert Decimals to floats.

        The *unit* and *axis* arguments are not used.

        Parameters
        ----------
        value : decimal.Decimal or iterable
            Decimal or list of Decimal need to be converted
        dtypeN)r   r   floatr   MaskedArrayasarrayr   )valuer    r!   r   r   r   r%      s
    
zDecimalConverter.convertN)r   r	   r
   r   r'   r%   r   r   r   r   r)      s   r)   c                   @   s   e Zd ZdZdd ZdS )Registryz)Register types with conversion interface.c              	   C   s   t |}t|tjrDtj| }|jsD| 	tj
dg|jdS t|jD ]&}z| | W   S  tyr   Y qN0 qNzt |}W n ttfy   Y n0 t|t|ur| 	|S dS )z6Get the converter interface instance for *x*, or None.r   r*   N)r   _unpack_to_numpyr   r   ndarrayr   getdataravelsizeget_converterarrayr+   type__mro__KeyError_safe_first_non_none	TypeErrorStopIteration)r   r   clsfirstr   r   r   r6      s"    

zRegistry.get_converterN)r   r	   r
   r   r6   r   r   r   r   r0      s   r0   )r   decimalr   numbersr   numpyr   r   
matplotlibr   r   r<   r   r   r   r   r)   dictr0   registryr   r   r   r   <module>   s   *$,!