rL i,i VdZddlZddlZddlZddlZddlmZmZddl m Z m Z m Z m Z mZmZmZmZmZmZmZddlmZmZGddZGdd eZGd d eZGd d eZGddeZGddeZGddeZGddeZGddeZ GddeZ!GddeZ"GddeZ#GddeZ$Gd d!eZ%Gd"d#eZ&Gd$d%eZ'Gd&d'eZ(eee"e%e(eed(Z)d)Z*d*Z+e+jr1e+jd+d,jYe-e.e*ize+_d-Z/d.Z0ejbjed/d,jYe*Dcgc] }e.| c}ze0jg0ycc}w)1a Scales define the distribution of data values on an axis, e.g. a log scaling. The mapping is implemented through `.Transform` subclasses. The following scales are built-in: .. _builtin_scales: ============= ===================== ================================ ================================= Name Class Transform Inverted transform ============= ===================== ================================ ================================= "asinh" `AsinhScale` `AsinhTransform` `InvertedAsinhTransform` "function" `FuncScale` `FuncTransform` `FuncTransform` "functionlog" `FuncScaleLog` `FuncTransform` + `LogTransform` `InvertedLogTransform` + `FuncTransform` "linear" `LinearScale` `.IdentityTransform` `.IdentityTransform` "log" `LogScale` `LogTransform` `InvertedLogTransform` "logit" `LogitScale` `LogitTransform` `LogisticTransform` "symlog" `SymmetricalLogScale` `SymmetricalLogTransform` `InvertedSymmetricalLogTransform` ============= ===================== ================================ ================================= A user will often only use the scale name, e.g. when setting the scale through `~.Axes.set_xscale`: ``ax.set_xscale("log")``. See also the :ref:`scales examples ` in the documentation. Custom scaling can be achieved through `FuncScale`, or by creating your own `ScaleBase` subclass and corresponding transforms (see :doc:`/gallery/scales/custom_scale`). Third parties can register their scales by name through `register_scale`. N)_api _docstring) NullFormatterScalarFormatterLogFormatterSciNotationLogitFormatter NullLocator LogLocator AutoLocatorAutoMinorLocatorSymmetricalLogLocator AsinhLocator LogitLocator) TransformIdentityTransformc(eZdZdZdZdZdZdZy) ScaleBasea The base class for all scales. Scales are separable transformations, working on a single dimension. Subclasses should override :attr:`name` The scale's name. :meth:`get_transform` A method returning a `.Transform`, which converts data coordinates to scaled coordinates. This transform should be invertible, so that e.g. mouse positions can be converted back to data coordinates. :meth:`set_default_locators_and_formatters` A method that sets default locators and formatters for an `~.axis.Axis` that uses this scale. :meth:`limit_range_for_scale` An optional method that "fixes" the axis range to acceptable values, e.g. restricting log-scaled axes to positive values. cy)a Construct a new scale. Notes ----- The following note is for scale implementers. For back-compatibility reasons, scales take an `~matplotlib.axis.Axis` object as first argument. However, this argument should not be used: a single scale object should be usable by multiple `~matplotlib.axis.Axis`\es at the same time. Nselfaxiss V/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/matplotlib/scale.py__init__zScaleBase.__init__Dct)zL Return the `.Transform` object associated with this scale. NotImplementedErrorrs r get_transformzScaleBase.get_transformRs "##rct)zi Set the locators and formatters of *axis* to instances suitable for this scale. rrs r#set_default_locators_and_formattersz-ScaleBase.set_default_locators_and_formattersXs "##rc ||fS)z Return the range *vmin*, *vmax*, restricted to the domain supported by this scale (if any). *minpos* should be the minimum positive value in the data. This is used by log scales to determine a minimum value. rrvminvmaxminposs rlimit_range_for_scalezScaleBase.limit_range_for_scale_sTzrN)__name__ __module__ __qualname____doc__rr!r#r)rrrrr.s*  $ $rrc&eZdZdZdZdZdZdZy) LinearScalez# The default linear scale. linearcy)z Nrrs rrzLinearScale.__init__qrrc|jt|jt|j t |j dk(rtjds"|j dk(r-tjdr|jty|jtyNxzxtick.minor.visibleyzytick.minor.visible set_major_locatorr set_major_formatterrset_minor_formatterr axis_namemplrcParamsset_minor_locatorr r rs rr#z/LinearScale.set_default_locators_and_formattersx {}-   !23   1 NNc !cll3H&I#%#,,7L*M  " "#3#5 6  " ";= 1rctS)z Return the transform for linear scaling, which is just the `~matplotlib.transforms.IdentityTransform`. )rr s rr!zLinearScale.get_transforms !""rN)r*r+r,r-namerr#r!rrrr/r/js D  2#rr/c6eZdZdZdxZZfdZdZdZxZ S) FuncTransformzi A simple transform that takes and arbitrary function for the forward and inverse transform. ct|t|rt|r||_||_yt d)a Parameters ---------- forward : callable The forward function for the transform. This function must have an inverse and, for best behavior, be monotonic. It must have the signature:: def forward(values: array-like) -> array-like inverse : callable The inverse of the forward function. Signature as ``forward``. z,arguments to FuncTransform must be functionsN)superrcallable_forward_inverse ValueError)rforwardinverse __class__s rrzFuncTransform.__init__s9  G '!2#DM#DMKL Lrc$|j|SN)rGrvaluess rtransform_non_affinez"FuncTransform.transform_non_affines}}V$$rcBt|j|jSrN)rBrHrGr s rinvertedzFuncTransform.invertedsT]]DMM::r r*r+r,r- input_dims output_dimsrrQrS __classcell__rLs@rrBrBs$ ! JM*%;rrBc&eZdZdZdZdZdZdZy) FuncScalezN Provide an arbitrary scale with user-supplied function for the axis. functionc4|\}}t||}||_y)a Parameters ---------- axis : `~matplotlib.axis.Axis` The axis for the scale. functions : (callable, callable) two-tuple of the forward and inverse functions for the scale. The forward function must be monotonic. Both functions must have the signature:: def forward(values: array-like) -> array-like N)rB _transform)rr functionsrJrK transforms rrzFuncScale.__init__s!%!'73 #rc|jS)z7Return the `.FuncTransform` associated with this scale.r]r s rr!zFuncScale.get_transform rc|jt|jt|j t |j dk(rtjds"|j dk(r-tjdr|jty|jtyr3r6rs rr#z-FuncScale.set_default_locators_and_formattersr>rN)r*r+r,r-r@rr!r#rrrrZrZs D$$ 2rrZc:eZdZdxZZdfd ZdZdZdZxZ S) LogTransformrCct||dks|dk(r td||_t j ddd||_y)NrrCz#The log base cannot be <= 0 or == 1TFclipmask nonpositive)rErrIbaser check_getitem_clip)rrlrkrLs rrzLogTransform.__init__sK  19 BC C ''5 ){D rcdjt|j|j|jrdSdS)Nz{}(base={}, nonpositive={!r})rhri)formattyper*rlrnr s r__str__zLogTransform.__str__sA.55 J  djjFN NFLN Nrctjdd5tjtjdtjdtj ij |j}|r ||}n7tj|}|tj|jz}|jrd||dk<ddd|S#1swYSxYw)Nignoredivideinvalid r) nperrstateeloglog2log10getrlrn)rrPr~outs rrQz!LogTransform.transform_non_affines [[( ; )44BGGR:>>tyyIC&kffVnrvvdii((zz$)FaK # )$ % )$ s B0CCc,t|jSrN)InvertedLogTransformrlr s rrSzLogTransform.inverteds#DII..r)rh r*r+r,rUrVrrrrQrSrWrXs@rreres#  JDN,/rrec8eZdZdxZZfdZdZdZdZxZ S)rrCc0t|||_yrN)rErrl)rrlrLs rrzInvertedLogTransform.__init__s  rcLt|jd|jdS)Nz(base=))rqr*rlr s rrrzInvertedLogTransform.__str__ s$t*%%&fTYYKq99rcBtj|j|SrN)r{powerrlrOs rrQz)InvertedLogTransform.transform_non_affine sxx 6**rc,t|jSrN)rerlr s rrSzInvertedLogTransform.invertedsDII&&rrrXs@rrrs!  J:+'rrcHeZdZdZdZdddddZedZd Zd Z d Z y) LogScalezT A standard logarithmic scale. Care is taken to only plot positive values. r~ryNrh)rlsubsrkc4t|||_||_y)a Parameters ---------- axis : `~matplotlib.axis.Axis` The axis for the scale. base : float, default: 10 The base of the logarithm. nonpositive : {'clip', 'mask'}, default: 'clip' Determines the behavior for non-positive values. They can either be masked as invalid, or clipped to a very small positive number. subs : sequence of int, default: None Where to place the subticks between each major tick. For example, in a log10 scale, ``[2, 3, 4, 5, 6, 7, 8, 9]`` will place 8 logarithmically spaced minor ticks between each major tick. N)rer]r)rrrlrrks rrzLogScale.__init__s 't[9 rc.|jjSrNr]rlr s rzLogScale.-!5!5rcV|jt|j|jt |j|j t|j|j |jt |j|j duy)N) labelOnlyBase)r7r rlr8rr=rr9rs rr#z,LogScale.set_default_locators_and_formatters/sx z$))45   !8!CD z$))TYY?@   #DII3799D3H K Lrc|jS)z6Return the `.LogTransform` associated with this scale.rar s rr!zLogScale.get_transform8rbrcVtj|sd}|dkr|n||dkr|fS|fS)z$Limit the domain to positive values.gYnrr{isfiniter%s rr)zLogScale.limit_range_for_scale<s>{{6"F!)!)/ /)-/ /r) r*r+r,r-r@rpropertyrlr#r!r)rrrrrs7 D%'d& 5 6DL/rrc2eZdZdZdZddZedZdZy) FuncScaleLogzu Provide an arbitrary scale with user-supplied function for the axis and then put on a logarithmic axes. functionlogcV|\}}d|_t||t|z|_y)a Parameters ---------- axis : `~matplotlib.axis.Axis` The axis for the scale. functions : (callable, callable) two-tuple of the forward and inverse functions for the scale. The forward function must be monotonic. Both functions must have the signature:: def forward(values: array-like) -> array-like base : float, default: 10 Logarithmic base of the scale. N)rrBrer])rrr^rlrJrKs rrzFuncScaleLog.__init__Ms-"% '9L >r r*r+r,rUrVrrQrSrWrXs@rrrks  J &>rrc2eZdZdxZZfdZdZdZxZS)rrCct|t|||}||_||_|j ||_||_|d|jdzz z |_y)Nrr) rErrrlrr_ invlinthreshrr)rrlrrsymlogrLs rrz(InvertedSymmetricalLogTransform.__init__s^ (y(C "",,Y7  &# R*?@rctj|}tjdd5tj||jztj |j ||jz |jz z}||jk}ddd||jz |<|S#1swY xYwr) r{rr|rrrrlrrrs rrQz4InvertedSymmetricalLogTransform.transform_non_affinesv [[( ; 0''&/DNN2/$2D2DDFGCd///F  0 Vnt'9'99F   0 0s A-B99CcXt|j|j|jSrN)rrlrrr s rrSz(InvertedSymmetricalLogTransform.inverteds$&tyy'+~~t}}F FrrrXs@rrrs  JBFrrcheZdZdZdZddddddZed Zed Zed Z d Z d Z y)SymmetricalLogScaleac The symmetrical logarithmic scale is logarithmic in both the positive and negative directions from the origin. Since the values close to zero tend toward infinity, there is a need to have a range around zero that is linear. The parameter *linthresh* allows the user to specify the size of this range (-*linthresh*, *linthresh*). See :doc:`/gallery/scales/symlog_demo` for a detailed description. Parameters ---------- base : float, default: 10 The base of the logarithm. linthresh : float, default: 2 Defines the range ``(-x, x)``, within which the plot is linear. This avoids having the plot go to infinity around zero. subs : sequence of int Where to place the subticks between each major tick. For example, in a log10 scale: ``[2, 3, 4, 5, 6, 7, 8, 9]`` will place 8 logarithmically spaced minor ticks between each major tick. linscale : float, optional This allows the linear range ``(-linthresh, linthresh)`` to be stretched relative to the logarithmic range. Its value is the number of decades to use for each half of the linear range. For example, when *linscale* == 1.0 (the default), the space used for the positive and negative halves of the linear range will be equal to one decade in the logarithmic range. rryrxNrC)rlrrrc6t||||_||_yrN)rr]r)rrrlrrrs rrzSymmetricalLogScale.__init__s1$ 8L rc.|jjSrNrr s rrzSymmetricalLogScale.rrc.|jjSrN)r]rr s rrzSymmetricalLogScale.sdoo&?&?rc.|jjSrN)r]rr s rrzSymmetricalLogScale.sT__%=%=rc4|jt|j|jt |j |j t|j|j|jtyrN) r7r r!r8rrlr=rr9rrs rr#z7SymmetricalLogScale.set_default_locators_and_formatterssq 4T5G5G5IJK   !8!CD 4T5G5G5I59YY @ A   1rc|jS)zAReturn the `.SymmetricalLogTransform` associated with this scale.rar s rr!z!SymmetricalLogScale.get_transformrbr) r*r+r,r-r@rrrlrrr#r!rrrrrsJ B D%'14! 5 6D?@I=>H2rrc6eZdZdZdxZZfdZdZdZxZ S)AsinhTransformz  J)G1rrc deZdZdZdZddddddddd Zd d d d fd ZedZdZ dZ xZ S) AsinhScalea A quasi-logarithmic scale based on the inverse hyperbolic sine (asinh) For values close to zero, this is essentially a linear scale, but for large magnitude values (either positive or negative) it is asymptotically logarithmic. The transition between these linear and logarithmic regimes is smooth, and has no discontinuities in the function gradient in contrast to the `.SymmetricalLogScale` ("symlog") scale. Specifically, the transformation of an axis coordinate :math:`a` is :math:`a \rightarrow a_0 \sinh^{-1} (a / a_0)` where :math:`a_0` is the effective width of the linear region of the transformation. In that region, the transformation is :math:`a \rightarrow a + \mathcal{O}(a^3)`. For large values of :math:`a` the transformation behaves as :math:`a \rightarrow a_0 \, \mathrm{sgn}(a) \ln |a| + \mathcal{O}(1)`. .. note:: This API is provisional and may be revised in the future based on early user feedback. asinh)rx)rx)rx)rxr)r)i)rrrryr@irryauto)rrlrc t||t||_t ||_|dk(r+|j j|j |_y||_y)a  Parameters ---------- linear_width : float, default: 1 The scale parameter (elsewhere referred to as :math:`a_0`) defining the extent of the quasi-linear region, and the coordinate values beyond which the transformation becomes asymptotically logarithmic. base : int, default: 10 The number base used for rounding tick locations on a logarithmic scale. If this is less than one, then rounding is to the nearest integer multiple of powers of ten. subs : sequence of int Multiples of the number base used for minor ticks. If set to 'auto', this will use built-in defaults, e.g. (2, 5) for base=10. rN) rErrr]int_baseauto_tick_multipliersr_subs)rrrrlrkwargsrLs rrzAsinhScale.__init__&sS( (6Y 6>3377 CDJDJrc.|jjSrN)r]rr s rrzAsinhScale.Bs)E)Erc|jSrNrar s rr!zAsinhScale.get_transformDs rcX|jt|j|jt|j|j|jt |jdkDr%|j t|jy|j dy)N)rl)rlr) major_locator minor_locatorminor_formatterrCz{x:.3g})setrrrrrr8rrs rr#z.AsinhScale.set_default_locators_and_formattersGs |D,=,=15 =+D,=,=1515 ="/  2 ::>  $ $%>rri r*r+r,rUrVrrQrSrrrWrXs@rrrTs"  J@ 4?rrc:eZdZdxZZdfd ZdZdZdZxZ S)rrCc0t|||_yrN)rErrrs rrzLogisticTransform.__init__ps 'rcddd| zzz S)zlogistic transform (base 10)rrCryrrOs rrQz&LogisticTransform.transform_non_affinetsa"w-'((rc,t|jSrN)rrr s rrSzLogisticTransform.invertedxrrcLt|jd|jdSrrr s rrrzLogisticTransform.__str__{rrrrrXs@rrrms!  J()1?rrc6eZdZdZdZd ddddZdZdZd Zy ) LogitScalez Logit scale for data between zero and one, both excluded. This scale is similar to a log scale close to zero and to one, and almost linear around 0.5. It maps the interval ]0, 1[ onto ]-infty, +infty[. logitz \frac{1}{2}Fone_half use_overlinec@t||_||_||_y)a Parameters ---------- axis : `~matplotlib.axis.Axis` Currently unused. nonpositive : {'mask', 'clip'} Determines the behavior for values beyond the open interval ]0, 1[. They can either be masked as invalid, or clipped to a number very close to 0 or 1. use_overline : bool, default: False Indicate the usage of survival notation (\overline{x}) in place of standard notation (1-x) for probability close to one. one_half : str, default: r"\frac{1}{2}" The string used for ticks formatter to represent 1/2. N)rr] _use_overline _one_half)rrrkrrs rrzLogitScale.__init__s")5)!rc|jS)z8Return the `.LogitTransform` associated with this scale.rar s rr!zLogitScale.get_transformrbrc.|jt|jt|j|j |j td|jtd|j|j y)NrT)minor)r rr)r7rr8rr rr=r9rs rr#z.LogitScale.set_default_locators_and_formatterssx |~.   !//  |$78   !//  rc\tj|sd}|dkr|n||dk\rd|z fS|fS)zH Limit the domain to values between 0 and 1 (excluded). gHz>rrCrr%s rr)z LogitScale.limit_range_for_scalesD{{6"F!)"aiF 3 3-13 3rNr) r*r+r,r-r@rr!r#r)rrrrrs, D"(u"* &3rr)r0r~rrrr[rc ttS)z)Return the names of the available scales.)sorted_scale_mappingrrrget_scale_namesrs . !!rc Jtjt|}||fi|S)z Return a scale class by name. Parameters ---------- scale : {%(names)s} axis : `~matplotlib.axis.Axis` )scale)rrmr)rrr scale_clss r scale_factoryrs&"">?I T $V $$rnamesz, c*|t|j<y)z Register a new kind of scale. Parameters ---------- scale_class : subclass of `ScaleBase` The scale to register. N)rr@) scale_classs rregister_scalers(3N;##$rc g}tjD]T\}}tj|jxsd}|j d|dt j|ddgVdj|S)zF Helper function for generating docstrings related to scales. z z  ) ritemsinspectgetdocrextendtextwrapindentjoin)docsr@r docstrings r_get_scale_docsr&s} D+113 kNN;#7#78>B  4(O  OOIw /      99T?rz{%s}) scale_type scale_docs)4r-rr!numpyr{ matplotlibr;rrmatplotlib.tickerrrrrr r r r r rrmatplotlib.transformsrrrr/rBrZrerrrrrrrrrrrrrrrr#mapreprrr&interpdregisterrstrip)r4s0rr2s>'7777?99x#)#D!;I!;H'2 '2T&/9&/R'9'"./y./b#8#L>i>@FiF66)6r9Y9$ 1Y 1Q0Q0h?Y?2? ?$<3<3@!" %)113t_%6785::M 3    O4E"Fq47"FGG '')"Fs4F&