rL idZddlmZddlZddlZddlZddlZddl m Z m Z m Z m Z ejeZGdde j"ZGdde j&ZGd d e j*ZGd d Zexe j0e<xe j0ej4<xe j0e<e j0ej8<y) 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)_apicbooktickerunitscLeZdZedZedZedZedZy)StrCategoryConverterch| tdtj|tjtj |t }|j|tj|jjtg|}tj|s|S|dS)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 zMissing category information for StrCategoryConverter; this might be caused by unintendedly mixing categorical and numeric datadtype)otypesr) ValueErrorr _validate_unitnp atleast_1darrayobjectupdate vectorize_mapping __getitem__floatris_scalar_or_string)valueunitaxisvaluesss Y/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/matplotlib/category.pyconvertzStrCategoryConverter.converts* <   ++D1rxxV<= F CBLL22E7 CF K11%8qBadBctj|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 )majlocmajfmt)r rStrCategoryLocatorrStrCategoryFormatterrAxisInfo)rrr#r$s raxisinfozStrCategoryConverter.axisinfo=sA( ++D1$DMM2%dmm4~~VF;;r!c|j&|jt||jS|jj||jS)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_unitsUnitDatar)datars r default_unitsz"StrCategoryConverter.default_unitsXsH" ::  NN8D> *zz JJ  d #zzr!c:t|dstd|dy)NrzProvided unit "zU" is not valid for a categorical converter, as it does not have a _mapping attribute.)hasattrr)rs rrz#StrCategoryConverter._validate_unitos3tZ(!$(GGH H)r!N)__name__ __module__ __qualname__ staticmethodr r(r-rr!rr r sUCCB<<4,HHr!r c"eZdZdZdZdZdZy)r%z1Tick at every integer mapping of the string data.c||_yz Parameters ---------- units_mapping : dict Mapping of category names (str) to indices (int). N_unitsself units_mappings r__init__zStrCategoryLocator.__init__y $ r!cHt|jjSN)listr9r)r;s r__call__zStrCategoryLocator.__call__sDKK&&())r!c|Sr@r4)r;vminvmaxs r tick_valueszStrCategoryLocator.tick_valuess v r!N)r0r1r2__doc__r=rBrFr4r!rr%r%ws;$*r!r%c4eZdZdZdZddZdZedZy)r&z0String representation of the data at every tick.c||_yr7r8r:s rr=zStrCategoryFormatter.__init__r>r!Nc,|j|gdS)Nr) format_ticks)r;xposs rrBzStrCategoryFormatter.__call__s  !%a((r!c|jjDcic]\}}||j|}}}|Dcgc]}|jt |dc}Scc}}wcc}w)N)r9items_textgetround)r;rkv r_mappingvals rrKz!StrCategoryFormatter.format_tickss\26++2C2C2EF$!QQ 1 %F F9?@# eCj"-@@G@s A&"A,ct|tr|jd}|St|ts t|}|S)z0Convert text values into utf-8 or ascii strings.zutf-8)encoding) isinstancebytesdecodestrrs rrQzStrCategoryFormatter._texts? eU #LL'L2E E3'JE r!r@) r0r1r2rGr=rBrKr3rQr4r!rr&r&s):$)A r!r&c*eZdZddZedZdZy)r+Nc|t|_tj|_||j |yy)z Create mapping between unique categorical values and integer ids. Parameters ---------- data : iterable sequence of string values N)rr itertoolscount_counterr)r;r,s rr=zUnitData.__init__s2$  !)   KK  r!c t|y#t$r9 tjj |Yy#tt f$rYYywxYwwxYw)zY Helper method to check whether a string can be parsed as float or date. FT)rrdateutilparserparse TypeError)rWs r_str_is_convertiblezUnitData._str_is_convertiblesY   #J   %%c* *   s$  A9A A A  Actjtj|t}d}t j |D]g}t jttf||r|j|}||jvsFt|j|j|<i|jr|rtj!dyyy)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)rrrrrfromkeysrcheck_isinstancer]r[rirnextrcsize_loginfo)r;r, convertiblerWs rrzUnitData.updates}}RXXd&9: ''- 9C  ! !3,c :"66s; $--'%)$--%8 c" 9 99 II? @%9r!r@)r0r1r2r=r3rirr4r!rr+r+s!   @r!r+)rG collectionsrdateutil.parserreraloggingnumpyr matplotlibrrrr getLoggerr0roConversionInterfacer Locatorr% Formatterr&r+registryr]str_r[bytes_r4r!rr~s $11w"ZH544ZHz(6++<:@:@D!5 67s7 NN2777 NN5 NN299r!