
    Ng                        d Z ddlmZ ddlZddlZddlZddlZddl	m
Z
mZmZ  ej        e          Z G d dej                  Z G d dej                  Z G d	 d
ej                  Z G d d          Z e            ej        e<    e            ej        ej        <    e            ej        e<    e            ej        ej        <   dS )a  
Plotting of string "category" data: ``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 and provides a tick locator, a tick formatter, and the
`.UnitData` class that creates and stores the string-to-integer mapping.
    )OrderedDictN)_apitickerunitsc                   f    e Zd Zed             Zed             Zed             Zed             ZdS )StrCategoryConverterc                 :   |t          d          t                              |           t          j        t          j        | t                              }|                    |            t          j        |j	        j
        t          g          |          S )a  
        Convert strings in *value* to floats using mapping information stored
        in the *unit* object.

        Parameters
        ----------
        value : str or iterable
            Value or list of values to be converted.
        unit : `.UnitData`
            An object mapping strings to integers.
        axis : `~matplotlib.axis.Axis`
            The axis on which the converted value is plotted.

            .. note:: *axis* is unused.

        Returns
        -------
        float or `~numpy.ndarray` of float
        NzMissing category information for StrCategoryConverter; this might be caused by unintendedly mixing categorical and numeric datadtype)otypes)
ValueErrorr   _validate_unitnp
atleast_1darrayobjectupdate	vectorize_mapping__getitem__float)valueunitaxisvaluess       O/var/www/html/ai-engine/env/lib/python3.11/site-packages/matplotlib/category.pyconvertzStrCategoryConverter.convert   s    * <      	++D111rxV<<<==FFr|DM5ugFFFvNNN    c                     t                               |            t          | j                  }t	          | j                  }t          j        ||          S )a  
        Set the default axis ticks and labels.

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

            .. note:: *axis* is not used

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

        )majlocmajfmt)r   r   StrCategoryLocatorr   StrCategoryFormatterr   AxisInfo)r   r   r    r!   s       r   axisinfozStrCategoryConverter.axisinfo<   sM    ( 	++D111 $DM22%dm44~VF;;;;r   c                     |j         #|                    t          |                      n|j                             |            |j         S )aO  
        Set and update the `~matplotlib.axis.Axis` units.

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

        Returns
        -------
        `.UnitData`
            object storing string to integer mapping
        )r   	set_unitsUnitDatar   )datar   s     r   default_unitsz"StrCategoryConverter.default_unitsW   sE    " :NN8D>>****Jd###zr   c                 L    t          | d          st          d|  d          d S )Nr   zProvided unit "zU" is not valid for a categorical converter, as it does not have a _mapping attribute.)hasattrr   )r   s    r   r   z#StrCategoryConverter._validate_unitn   sP    tZ(( 	HG$ G G GH H H	H 	Hr   N)__name__
__module____qualname__staticmethodr   r%   r*   r    r   r   r   r      s        O O \O@ < < \<4   \, H H \H H Hr   r   c                   $    e Zd ZdZd Zd Zd ZdS )r"   z1Tick at every integer mapping of the string data.c                     || _         dS z
        Parameters
        ----------
        units_mapping : dict
            Mapping of category names (str) to indices (int).
        N_unitsselfunits_mappings     r   __init__zStrCategoryLocator.__init__x        $r   c                 N    t          | j                                                  S N)listr6   r   )r8   s    r   __call__zStrCategoryLocator.__call__   s    DK&&(()))r   c                      |             S r=   r1   )r8   vminvmaxs      r   tick_valueszStrCategoryLocator.tick_values   s    tvvr   N)r-   r.   r/   __doc__r:   r?   rC   r1   r   r   r"   r"   v   sG        ;;$ $ $* * *    r   r"   c                   <    e Zd ZdZd ZddZd Zed             ZdS )r#   z0String representation of the data at every tick.c                     || _         dS r4   r5   r7   s     r   r:   zStrCategoryFormatter.__init__   r;   r   Nc                 :    |                      |g          d         S )Nr   )format_ticks)r8   xposs      r   r?   zStrCategoryFormatter.__call__   s      !%%a((r   c                 l      fd j                                         D             fd|D             S )Nc                 B    i | ]\  }}|                     |          S r1   )_text).0kvr8   s      r   
<dictcomp>z5StrCategoryFormatter.format_ticks.<locals>.<dictcomp>   s)    FFF$!QQ

1FFFr   c                 V    g | ]%}                     t          |          d           &S ) )getround)rN   val	r_mappings     r   
<listcomp>z5StrCategoryFormatter.format_ticks.<locals>.<listcomp>   s-    @@@#	eCjj"--@@@r   )r6   items)r8   r   rW   s   ` @r   rH   z!StrCategoryFormatter.format_ticks   sE    FFFF$+2C2C2E2EFFF	@@@@@@@@r   c                     t          | t                    r|                     d          } n$t          | t                    st          |           } | S )z0Convert text values into utf-8 or ascii strings.zutf-8)encoding)
isinstancebytesdecodestrr   s    r   rM   zStrCategoryFormatter._text   sM     eU## 	LL'L22EEE3'' 	JJEr   r=   )	r-   r.   r/   rD   r:   r?   rH   r0   rM   r1   r   r   r#   r#      sj        ::$ $ $) ) ) )A A A
   \  r   r#   c                   2    e Zd ZddZed             Zd ZdS )r(   Nc                     t                      | _        t          j                    | _        ||                     |           dS dS )z
        Create mapping between unique categorical values and integer ids.

        Parameters
        ----------
        data : iterable
            sequence of string values
        N)r   r   	itertoolscount_counterr   )r8   r)   s     r   r:   zUnitData.__init__   sD     $!))KK r   c                     	 t          |            nJ# t          $ r= 	 t          j                            |            n# t          t
          f$ r Y Y dS w xY wY nw xY wdS )zY
        Helper method to check whether a string can be parsed as float or date.
        FT)r   r   dateutilparserparse	TypeError)rV   s    r   _str_is_convertiblezUnitData._str_is_convertible   s    
	#JJJJ 	 	 	%%c****	*   uuu +*	 ts/    
A=AAAAAAc                    t          j        t          j        |t                              }d}t	          j        |          D ]`}t          j        t          t          f|           |r| 
                    |          }|| j        vrt          | j                  | j        |<   a|j        r|rt                              d           dS dS dS )z
        Map new values to integer identifiers.

        Parameters
        ----------
        data : iterable of str or bytes

        Raises
        ------
        TypeError
            If elements in *data* are neither str nor bytes.
        r
   Tr`   zUsing categorical units to plot a list of strings that are all parsable as floats or dates. If these strings should be plotted as numbers, cast to the appropriate data type before plotting.N)r   r   r   r   r   fromkeysr   check_isinstancer_   r]   rk   r   nextre   size_loginfo)r8   r)   convertiblerV   s       r   r   zUnitData.update   s     }RXd&999::'-- 	9 	9C!3,c:::: <"66s;;$-''%)$-%8%8c"9 	@ 	@II ? @ @ @ @ @	@ 	@ 	@ 	@r   r=   )r-   r.   r/   r:   r0   rk   r   r1   r   r   r(   r(      sW              \@ @ @ @ @r   r(   )rD   collectionsr   dateutil.parserrg   rc   loggingnumpyr   
matplotlibr   r   r   	getLoggerr-   rq   ConversionInterfacer   Locatorr"   	Formatterr#   r(   registryr_   str_r]   bytes_r1   r   r   <module>r      s  
 
 $ # # # # #              * * * * * * * * * * w""YH YH YH YH YH54 YH YH YHx       (    6+   <:@ :@ :@ :@ :@ :@ :@ :@| +*,,s ..00rw ,,..u 0022ry   r   