
    P/Ph                     n   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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            xej        e<   xej        ej        <   xej        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cbooktickerunitsc                   f    e Zd Zed             Zed             Zed             Zed             ZdS )StrCategoryConverterc                 v   |t          d          t                              |           t          j        t          j        | t                              }|                    |            t          j        |j	        j
        t          g          |          }t          j        |           s|n|d         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)otypesr   )
ValueErrorr	   _validate_unitnp
atleast_1darrayobjectupdate	vectorize_mapping__getitem__floatr   is_scalar_or_string)valueunitaxisvaluesss        S/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/matplotlib/category.pyconvertzStrCategoryConverter.convert   s    * <      	++D111rxV<<<==FCBL2E7CCCFKK1%88BqqadB    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_unitsX   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_unito   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        C C \CB < < \<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__y        $r!   c                 N    t          | j                                                  S N)listr9   r   )r;   s    r   __call__zStrCategoryLocator.__call__   s    DK&&(()))r!   c                      |             S r@   r4   )r;   vminvmaxs      r   tick_valueszStrCategoryLocator.tick_values   s    tvvr!   N)r0   r1   r2   __doc__r=   rB   rF   r4   r!   r   r%   r%   w   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 r7   r8   r:   s     r   r=   zStrCategoryFormatter.__init__   r>   r!   Nc                 :    |                      |g          d         S )Nr   )format_ticks)r;   xposs      r   rB   zStrCategoryFormatter.__call__   s      !%%a((r!   c                 l      fd j                                         D             fd|D             S )Nc                 B    i | ]\  }}|                     |          S r4   )_text).0kvr;   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)rQ   val	r_mappings     r   
<listcomp>z5StrCategoryFormatter.format_ticks.<locals>.<listcomp>   s-    @@@#	eCjj"--@@@r!   )r9   items)r;   r   rZ   s   ` @r   rK   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   rP   zStrCategoryFormatter._text   sM     eU## 	LL'L22EEE3'' 	JJEr!   r@   )	r0   r1   r2   rG   r=   rB   rK   r3   rP   r4   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   )r;   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)rY   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   Trc   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_isinstancerb   r`   rn   r   nextrh   size_loginfo)r;   r,   convertiblerY   s       r   r   zUnitData.update   s     }RXd&999::'-- 	9 	9C!3,c:::: <"66s;;$-''%)$-%8%8c"9 	@ 	@II ? @ @ @ @ @	@ 	@ 	@ 	@r!   r@   )r0   r1   r2   r=   r3   rn   r   r4   r!   r   r+   r+      sW              \@ @ @ @ @r!   r+   )rG   collectionsr   dateutil.parserrj   rf   loggingnumpyr   
matplotlibr   r   r   r   	getLoggerr0   rt   ConversionInterfacer	   Locatorr%   	Formatterr&   r+   registryrb   str_r`   bytes_r4   r!   r   <module>r      s  
 
 $ # # # # #              1 1 1 1 1 1 1 1 1 1 1 1 w""ZH ZH ZH ZH ZH54 ZH ZH ZHz       (    6+   <:@ :@ :@ :@ :@ :@ :@ :@D !5 4 6 67s  7	N277	N5	N29r!   