
    h                        S r SSKJr  SSKrSSKrSSKrSSKrSSK	J
r
JrJrJr  \R                  " \5      r " S S\R"                  5      r " S S\R&                  5      r " S	 S
\R*                  5      r " S S5      r\" 5       =\R0                  \'   =\R0                  \R4                  '   =\R0                  \'   \R0                  \R8                  '   g)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                   T    \ rS rSr\S 5       r\S 5       r\S 5       r\S 5       rSr	g)StrCategoryConverter   c                 p   Uc  [        S5      e[        R                  U5        [        R                  " [        R
                  " U [        S95      nUR                  U5        [        R                  " UR                  R                  [        /S9" U5      n[        R                  " U 5      (       d  U$ U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
z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        E/var/www/html/env/lib/python3.13/site-packages/matplotlib/category.pyconvertStrCategoryConverter.convert   s    * <    	++D1rxxV<=FLL22E7CFK11%88qBadB    c                     [         R                  U 5        [        U R                  5      n[	        U R                  5      n[
        R                  " X#S9$ )aL  
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    axisinfoStrCategoryConverter.axisinfo=   s?    ( 	++D1 $DMM2%dmm4~~V;;r#   c                     UR                   c&  UR                  [        U 5      5        UR                   $ UR                   R                  U 5        UR                   $ )z
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_units"StrCategoryConverter.default_unitsX   sH    " ::NN8D>* zz JJd#zzr#   c                 D    [        U S5      (       d  [        SU  S35      eg )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   #StrCategoryConverter._validate_unito   s6    tZ((!$ (G GH H )r#    N)
__name__
__module____qualname____firstlineno__staticmethodr!   r*   r0   r   __static_attributes__r5   r#   r    r	   r	      sU    C CB < <4  , H Hr#   r	   c                   *    \ rS rSrSrS rS rS rSrg)r'   w   z1Tick at every integer mapping of the string data.c                     Xl         gzb
Parameters
----------
units_mapping : dict
    Mapping of category names (str) to indices (int).
N_unitsselfunits_mappings     r    __init__StrCategoryLocator.__init__y   	     $r#   c                 H    [        U R                  R                  5       5      $ N)listrA   r   )rC   s    r    __call__StrCategoryLocator.__call__   s    DKK&&())r#   c                     U " 5       $ rI   r5   )rC   vminvmaxs      r    tick_valuesStrCategoryLocator.tick_values   s	    vr#   r@   N)	r6   r7   r8   r9   __doc__rE   rK   rP   r;   r5   r#   r    r'   r'   w   s    ;$*r#   r'   c                   >    \ rS rSrSrS rS	S jrS r\S 5       r	Sr
g)
r(      z0String representation of the data at every tick.c                     Xl         gr?   r@   rB   s     r    rE   StrCategoryFormatter.__init__   rG   r#   Nc                 ,    U R                  U/5      S   $ )Nr   )format_ticks)rC   xposs      r    rK   StrCategoryFormatter.__call__   s      !%a((r#   c                     U R                   R                  5        VVs0 s H  u  p#X0R                  U5      _M     nnnU Vs/ s H  oTR                  [	        U5      S5      PM     sn$ s  snnf s  snf )N )rA   items_textgetround)rC   r   kv	r_mappingvals         r    rX   !StrCategoryFormatter.format_ticks   s]    26++2C2C2EF2E$!Q

1%2E	F9?@#eCj"-@@ G@s   A)$A/c                     [        U [        5      (       a  U R                  SS9n U $ [        U [        5      (       d  [        U 5      n U $ )z0Convert text values into utf-8 or ascii strings.zutf-8)encoding)
isinstancebytesdecodestrr   s    r    r_   StrCategoryFormatter._text   sE     eU##LL'L2E  E3''JEr#   r@   rI   )r6   r7   r8   r9   rR   rE   rK   rX   r:   r_   r;   r5   r#   r    r(   r(      s)    :$)A
  r#   r(   c                   4    \ rS rSrSS jr\S 5       rS rSrg)r.      Nc                     [        5       U l        [        R                  " 5       U l        Ub  U R                  U5        gg)z
Create mapping between unique categorical values and integer ids.

Parameters
----------
data : iterable
    sequence of string values
N)r   r   	itertoolscount_counterr   )rC   r/   s     r    rE   UnitData.__init__   s2     $!)KK r#   c                      [        U 5        g! [         a:     [        R                  R	                  U 5         g! [        [
        4 a      gf = ff = f)zI
Helper method to check whether a string can be parsed as float or date.
FT)r   r   dateutilparserparse	TypeError)re   s    r    _str_is_convertibleUnitData._str_is_convertible   sY    
	#J   	%%c*  	* 	s$    
A:A
AAAc                    [         R                  " [         R                  " U[        S95      nSn[        R
                  " U5       Hm  n[        R                  " [        [        4US9  U(       a  U R                  U5      nX0R                  ;  d  MK  [        U R                  5      U R                  U'   Mo     UR                  (       a  U(       a  [        R!                  S5        ggg)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   Trm   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_isinstancerl   rj   r{   r   nextrt   size_loginfo)rC   r/   convertiblere   s       r    r   UnitData.update   s     }}RXXd&9:''-C!!3,c:"66s;--'%)$--%8c" . 99II ? @ %9r#   )rt   r   rI   )	r6   r7   r8   r9   rE   r:   r{   r   r;   r5   r#   r    r.   r.      s!      @r#   r.   )rR   collectionsr   dateutil.parserrw   rr   loggingnumpyr   
matplotlibr   r   r   r   	getLoggerr6   r   ConversionInterfacer	   Locatorr'   	Formatterr(   r.   registryrl   str_rj   bytes_r5   r#   r    <module>r      s   
 $     1 1 "ZH544 ZHz (6++ <:@ :@D !5 67s  7	NN2777	NN5	NN299r#   