L iqdZddlZddlZddlZddlZddlmZddlmZm Z ddl m Z ddl Z ddlZddlZddlmZddlmZddlmZddlmZdd lmZdd lmZgd Zd Z e d Z!dZ"dZ#d/dZ$dZ%dZ&d0dZ'dZ(dZ)dZ* d1dZ+dZ,dZ-d2dZ.dZ/d3dZ0d4dZ1dZ2dZ3d Z4d!Z5d"Z6d5d#Z7d$Z8d%Z9d&Z:d'Z;ed(Zfd,Z?d-Z@d.ZAy)6z+Utility functions, mostly for internal use.N)contextmanager)urlopen urlretrieve) ModuleType)to_rgb)normalize_kwargs) deprecated)Version)user_cache_dir) desaturatesaturateset_hls_values move_legenddespineget_dataset_names get_data_home load_datasetz=https://raw.githubusercontent.com/mwaskom/seaborn-data/masterz/dataset_names.txtcRtj|jdd}tj|}g}t tj |D]*\}\}}||}||z }||z }|j ||g,tj|j}|S)aConvert intervals to error arguments relative to plot heights. Parameters ---------- cis : 2 x n sequence sequence of confidence interval limits heights : n sequence sequence of plot heights Returns ------- errsize : 2 x n array sequence of error size relative to height values in correct format as argument for plt.bar ) np atleast_2dreshape atleast_1d enumerate transposeappendasarrayT) cisheightserrsizeilowhighhelowehighs S/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/seaborn/utils.py ci_to_errsizer*s" --  $ $Q +CmmG$GG#BLL$56&;C AJ3wqe}% & jj!##G Nc|jj|jr+ |j|jjyy#t$rYywxYw)z>Force draw of a matplotlib figure, accounting for back-compat.N)canvasdrawstale get_rendererAttributeError)figs r) _draw_figurer3:sPJJOO yy  HHSZZ,,. /   s)A AAc|yjjdd||dkr t||}|S|jdk(rdt t j jjd}|ggdd|\}|j}|jn|jdk(rtfd d D}tj|tjx}}|||fi}|j} t!| sd} n'tj"| d j$d dk(} d vr| rt'| d }|jn|jdk(ry|tjgtjgfi\}t'|j)}|j|j*j,jdnk|jdk(r\t t j.j0|ggfi}|j)} t'| d }|j|dkr t||}|S)zFIf needed, get a default color by using the matplotlib property cycle.NlabelplotcolorF)scalexscaleyr8scatterc3K|]6}tjj|gjd8yw)rN)rrgetshape).0keykwss r) z!_default_color..cs8  MM#''#r* + 1 1! 4 sr get_facecolor__self__ containers collectionsPolyCollection) methodhuer8rA saturationscout scout_sizescout_xscout_yrG single_colorrFs ` r)_default_colorrfEs   ((*CGGGT  >uj1E F " cii&6&67;;GDBuU%H!  I % B  GGJ77'w/3/))+ : !L99Za8>>qAQFL c>l:a=)E  E !266(2c2u**,- ""&&r* N *sCOO$B$BCr2%%'') y|$ A~5*- Lr+cd|cxkrdkstdtdt|}|dk(r|Stj|\}}}||z}tj|||}|S)alDecrease the saturation channel of a color by some percent. Parameters ---------- color : matplotlib color hex, rgb-tuple, or html color name prop : float saturation channel of color will be multiplied by this value Returns ------- new_color : rgb tuple desaturated color code in RGB tuple representation rr6zprop must be between 0 and 1) ValueErrorrcolorsys rgb_to_hls hls_to_rgb)r8proprgbr&lrC new_colors r)r r s" >>788 788 -C qy !!3'GAq!IA##Aq!,I r+ct|dS)a Return a fully saturated color with the same hue. Parameters ---------- color : matplotlib color hex, rgb-tuple, or html color name Returns ------- new_color : rgb tuple saturated color code in RGB tuple representation r6)rC)r)r8s r)r r s %1 %%r+ct|}ttj|}t |||gD] \}}| |||<tj |}|S)anIndependently manipulate the h, l, or s channels of a color. Parameters ---------- color : matplotlib color hex, rgb-tuple, or html color name h, l, s : floats between 0 and 1, or None new values for each channel in hls space Returns ------- new_color : rgb tuple new color code in RGB tuple representation )rlistrirjrrk)r8r&rnrCrmvalsr#vals r)rrse" -C ##S) *DQ1I&3 ?DG   t $C Jr+c d}tj|ttj}|j |fi||j |fi|y)z[Grab current axis and label it. DEPRECATED: will be removed in a future version. zCThis function is deprecated and will be removed in a future versionN)warningswarn FutureWarningpltgca set_xlabel set_ylabel)xlabelylabelkwargsmsgaxs r)axlabelrsI PC MM#}% BBMM&#F#BMM&#F#r+c2|tj|S)aGHelper method for removing null values from data vectors. Parameters ---------- vector : vector object Must implement boolean masking with [] subscript syntax. Returns ------- clean_clean : same type as ``vector`` Vector of data with null values removed. May be a copy or a view. )pdnotnull)vectors r) remove_nars "**V$ %%r+cptjd}d|jvr|jdSdgS)a Return the list of colors in the current matplotlib color cycle Parameters ---------- None Returns ------- colors : list List of matplotlib colors in the current cycle, or dark gray if the current color cycle is empty. zaxes.prop_cycler8z.15)rNrcParamskeysby_key)cyclers r)get_color_cyclers6\\+ ,F'.&++'=6==?7 #JE7Jr+c |!|tjj}n| |j}n||g}D];} dD]g} t|  } | j| j | |2| s5 |j | d} | j| jd| fi|r|std| jjD} td| jjD}| jjd| jjD]}|jj | | jjD]}|jj ||r|std| jjD} td | jjD}| jjd | jjD]}|jj | | jjD]}|jj ||s"t!j"| j%}|j&rt!j(|t+| j-k\|d}t!j(|t/| j-k|d }| jd j1||| jd j1|||j)||k}|j)||k\}| j3|t!j"| j5}|j&s_t!j(|t+| j7k\|d}t!j(|t/| j7k|d }| jd j1||| jdj1|||j)||k}|j)||k\}| j9|>y#t$r|} YwxYw)a Remove the top and right spines from plot(s). fig : matplotlib figure, optional Figure to despine all axes of, defaults to the current figure. ax : matplotlib axes, optional Specific axes object to despine. Ignored if fig is provided. top, right, left, bottom : boolean, optional If True, remove that spine. offset : int or dict, optional Absolute distance, in points, spines should be moved away from the axes (negative values move spines inward). A single value applies to all spines; a dict can be used to set offset values per side. trim : bool, optional If True, limit spines to the smallest and largest major tick on each non-despined axis. Returns ------- None N)toprightleftbottomroutwardc3PK|]}|jj ywN tick1line get_visibler?ts r)rBzdespine..C% '')$&c3PK|]}|jj ywrrrs r)rBzdespine..Grrrc3PK|]}|jj ywrrrs r)rBzdespine..Rrrc3PK|]}|jj ywrrrs r)rBzdespine..Vrrrrrr)rygcfaxeslocalsspines set_visibler=r1 set_positionanyyaxis majorTicks minorTicksset_ticks_position tick2linexaxisrr get_xtickssizecompressminget_xlimrS set_bounds set_xticks get_yticksget_ylim set_yticks)r2rrrrroffsettrimrax_iside is_visiblertmaj_onmin_onrxticks firstticklastticknewticksytickss r)rrs2 {rzwwy~~ xx tC*6 AD#Xd^+J KK  ) )* 5!j! **T1-C D!.. 3/?@ A ..F..F JJ ) )' 2ZZ** 0 ''/ 0ZZ** 0 ''/ 0 #..F..F JJ ) )% 0ZZ** 0 ''/ 0ZZ** 0 ''/ 0 ZZ 12F{{KK#dmmo2F(F(.0013 ;;vT]]_1E'E'-//13 H%00HE E"--iB!??6X+=>#,,X-BC)ZZ 12F{{KK#dmmo2F(F(.0013 ;;vT]]_1E'E'-//13 F#..y(C G$// 8D!??6X+=>#,,X-BC)GC*&! C!s6Q:: R R c Nddlm}t||r#|j}|jj}nt|t j jr|j}|j}n\t|t jjr+|jr|jd}nd}|j}n d}t|||d}t|ddl m}||}|jD cgc]} | j!} } |j#ddx} &t%| t%| k7r d }t|| } t'j(t jj*j,} |j/j1D cic] \} }| | vs | |}} }|j#d |j#d }d |vr |j3|j#d |j1D cic]\} }| j5d s| |}} }|j1D]-\}}|j6di|d d|i|j#|/|j9d|j:j=|j?||jA||| fd|i|}|jC|j!|jEt||r||_#yycc} wcc}} wcc}} w)a< Recreate a plot's legend at a new location. The name is a slight misnomer. Matplotlib legends do not expose public control over their position parameters. So this function creates a new legend, copying over the data from the original object, which is then removed. Parameters ---------- obj : the object with the plot This argument can be either a seaborn or matplotlib object: - :class:`seaborn.FacetGrid` or :class:`seaborn.PairGrid` - :class:`matplotlib.axes.Axes` or :class:`matplotlib.figure.Figure` loc : str or int Location argument, as in :meth:`matplotlib.axes.Axes.legend`. kwargs Other keyword arguments are passed to :meth:`matplotlib.axes.Axes.legend`. Examples -------- .. include:: ../docstrings/move_legend.rst r)GridrNzC`obj` must be a seaborn Grid or matplotlib Axes or Figure instance.z has no legend attached.)get_legend_handleslabelsz4Length of new labels does not match existing legend.bbox_to_anchortitletitle_frameonloc)$seaborn.axisgridr isinstancelegendfigurerNrAxeslegend_Figurelegends TypeErrorrhseaborn._compatr get_textsget_textrLrWinspect signatureLegend parameters propertiesitemsset_text startswithset setdefault legendPatchrupdaterR set_titleget_fontproperties_legend)objrrr old_legend legend_funcerrrhandlesrr new_labels legend_kwskvpropsr title_kwargsr@rt new_legends r)rr{s@&#tZZ jj'' C '[[ jj C** + ;;RJJjj Sn-.o3 ,G$.$8$8$: ;qajjl ;F ;jj400 = z?c&k )HCS/ !""3::#4#45@@J(335;;= QdajQT QE Q II IIg E& vzz'*+%+\\^NTQq||H7MAqDNLN &&(S #SWcN# 3  i!7!7!C!C!EF LLWf?#??J)5+C+C+EF#t  I< ROsL, L9LL!4L!ct|j||zz |d}t|j||zz|d}tj|||}|S)z0Establish support for a kernel density estimate.rr6)rSrrlinspace)databwgridsizecutclip support_min support_maxsupports r) _kde_supportrsWdhhj28+T!W5Kdhhj28+T!W5Kkk+{H=G Nr+cPd|dz z d|dz zf}tj|||S)z2Return a percentile range from an array of values.2r)r nanpercentile)awhichrHps r)cirs1 UQYUQY&A  Aq$ ''r+ctt5}|j}dddjj dDcgc]}|j }}t td|S#1swYXxYwcc}w)zkReport available example datasets, useful for reporting issues. Requires an internet connection. N )rDATASET_NAMES_URLreaddecodesplitstriprrfilter)resptxtname dataset_namess r)rrsr " #tiik/2jjl.@.@.FGdTZZ\GMG t]+ ,, HsA8 B8Bc|)tjjdtd}tjj |}tjj |stj||S)aLReturn a path to the cache directory for example datasets. This directory is used by :func:`load_dataset`. If the ``data_home`` argument is not provided, it will use a directory specified by the `SEABORN_DATA` environment variable (if it exists) or otherwise default to an OS-appropriate user cache location. SEABORN_DATAseaborn)osenvironr=r path expanduserexistsmakedirs) data_homes r)rrsYJJNN>>)3LM ""9-I 77>>) $ I r+c t|tjr d}t|td|d}|rt j jt|t j j|}t j j|s'|tvrtd|dt|||}n|}tj|fi|}|jdj!j#r|jdd}|dk(rztj$|d gd |d <tj$|d d d g|d <tj$|dddg|d<tj$|dddg|d<|S|dk(r;|dj&dd} tj$| | j)|d<|S|dk(r\tj$|dgd|d<tj$|dgd|d<tj$|dddg|d<|S|dk(rEtj$|dgd |d<tj$|d!t+d"|d!<|S|d#k(r"|d j&j-|d <|S|d$k(r\tj$|d%gd&|d%<tj$|d'gd(|d'<tj$|d)gd*|d)<|S|d+k(r8tj.|d,|d,<tj.|d-|d-<|S|d.k(rtj.|d/|d/<|S|d0k(rtj.|d/|d/<|S)1aLoad an example dataset from the online repository (requires internet). This function provides quick access to a small number of example datasets that are useful for documenting seaborn or generating reproducible examples for bug reports. It is not necessary for normal usage. Note that some of the datasets have a small amount of preprocessing applied to define a proper ordering for categorical variables. Use :func:`get_dataset_names` to see a list of available datasets. Parameters ---------- name : str Name of the dataset (``{name}.csv`` on https://github.com/mwaskom/seaborn-data). cache : boolean, optional If True, try to load from the local cache first, and save to the cache if a download is required. data_home : string, optional The directory in which to cache data; see :func:`get_data_home`. kws : keys and values, optional Additional keyword arguments are passed to passed through to :func:`pandas.read_csv`. Returns ------- df : :class:`pandas.DataFrame` Tabular data, possibly with some preprocessing applied. zThis function accepts only strings (the name of an example dataset). You passed a pandas DataFrame. If you have your own dataset, it is not necessary to use this function before plotting./z.csv'z%' is not one of the example datasets.rNtipsday)ThurFriSatSunsexMaleFemaletimeLunchDinnersmokerYesNoflightsmonthexercise)z1 minz15 minz30 minkind)restwalkingrunningdietzno fatzlow fattitanicclass)FirstSecondThirddeckABCDEFGpenguinsdiamondsr8)DEFGHIJclarity)IFVVS1VVS2VS1VS2SI1SI2I1r)IdealPremiumz Very GoodGoodFairtaxispickupdropoffseaiceDatedowjones)rr DataFramerDATASET_SOURCErrjoinrbasenamerrrhrread_csvilocisnullall CategoricalstrrXrrr to_datetime) rcacherrArurl cache_path full_pathdfmonthss r)rr spF$ % H n  AdV4 (C WW\\- ":BGG.dummy_axiscSrr)selflimitss r)get_view_intervalz?locator_to_legend_entries..dummy_axis.get_view_intervalsMr+N)rM __module__ __qualname__r~)r}sr) dummy_axisrzs r+rF) tick_valuesastyperrNticker LogLocator LogFormatterScalarFormatter set_useOffsetset_scientificrH format_ticks)locatorr}dtype raw_levelsrnr formatterformatted_levelss ` r)locator_to_legend_entriesrs$$$f-44U;J(M1q >a6!9n!MJM'3::001JJ++- JJ..0  &  '\IN --j9 ' ''%Ns C1C1C1ctjjj|ddddf}t j |dk|dz |dzdz dz}|j gd} |jS#t$r|cYSwxYw) aCalculate the relative luminance of a color according to W3C standards Parameters ---------- color : matplotlib color or sequence of matplotlib colors Hex code, rgb-tuple, or html color name. Returns ------- luminance : float(s) between 0 and 1 Nr1g#?gףp= )@g)\(?gzG?g333333@)gz6?g,C?g]m{?) rNcolorscolorConverter to_rgba_arrayrwheredotitemrh)r8rmlums r)relative_luminancers ** # # 1 1% 8BQB ?C ((3&=#+tu0D/L MC ''' (Cxxz  s-A== B  B ct|tr|S |jdS#t$rt|cYSwxYw)aReturn a string representing a Python object. Strings (i.e. type ``str``) are returned unchanged. Byte strings (i.e. type ``bytes``) are returned as UTF-8-decoded strings. For other objects, the method ``__str__()`` is called, and the result is returned as a string. Parameters ---------- obj : object Any Python object Returns ------- s : str UTF-8-decoded string representation of ``obj`` zutf-8)encoding)rrdr r1)rs r)to_utf8rsA*#s zz7z++ 3xs &==c |rtfd|D }n|v}|rtd|d|dtdS)z+Raise if value for param is not in options.c3bK|]&}t|tsj|(ywr)rrdr)r?rvalues r)rBz"_check_argument..s&U!*QPSBT%**1-Us//zThe value for `z` must be one of z, but z was passed.)rrhrepr)paramoptionsrprefixfailures ` r)_check_argumentrsb %#UwUUUw&eW$5gY?;-| -   Lr+ctj|j}tj|j}|D]}||vs||vs ||j||< |S)zBAssign default kwargs for call_func using values from source_func.)rrrdefault)rA call_func source_funcneededdefaultsrs r)_assign_default_kwargsrsh  y ) 4 4F  -88H1 H c!1!%00CJ1 Jr+ctjjdd}|jtj j dj}|D]r}|j\}}|j}td|Dr9|jd|jD]}||j|ty)z Make invisible-handle "subtitles" entries look more like titles. Note: This function is not part of the public API and may be changed or removed. zlegend.title_fontsizeNrc3<K|]}|jywr)r)r?artists r)rBz*adjust_legend_subtitles..s>F6%%'>s) ryrr=findobjrN offsetboxVPacker get_childrenrb set_widthset_size)r font_sizehpackershpack draw_area text_areartexts r)adjust_legend_subtitlesrs   !8$?I~~cmm334Q7DDFH-$113 9((*>g>>    "!..0 -(MM), - -r+c|turA|dk7r<|d}n |dk(rd}nd|f}dt|d}tj|td|S) a Warn on usage of ci= and convert to appropriate errorbar= arg. ci was deprecated when errorbar was added in 0.12. It should not be removed completely for some time, but it can be moved out of function definitions (and extracted from kwargs) after one cycle. r Nsdrz2 The `ci` parameter is deprecated. Use `errorbar=z` for the same effect. r1) stacklevel)r rrvrwrx)errorbarrrs r) _deprecate_cir#sf l 2 :H 4ZHbzH !(^,,D F   c=Q7 Or+ct||d}|j}|j|jjfS)z;Return the forward and inverse transforms for a given axis.rH)getattr get_transform transforminverted)rrHaxis_objrs r)_get_transform_functionsr<sBrdV4=)H&&(I    2 2 4 > > >>r+c#Ktjd} dtjd<d|tjd<y#|tjd<wxYww)zBContext manager for preventing rc-controlled auto-layout behavior.zfigure.autolayoutFN)rNr)orig_vals r)_disable_autolayoutrCsL||/0H5,1 () ,4 ()H ()sAAAAAlibversionreturncDt|jt|kS)z3Helper function for checking version compatibility.)r __version__)rrs r)_version_predatesrVs 3?? #gg&6 66r+c t|tjj}|j dd}tj }d|j ddt j|j d|ddz|j d|jd |j d d d |}||d k(r |d|d<n||d<tjjggfi|S)N edgecolormarkerorCzlines.markersizerrFr8 linewidthr) linestyler markersizemarkerfacecolormarkeredgewidthfacermarkeredgecolor) rrNr\PathCollectionrLrrsqrtr=rOrP)rArrcline_kwss r)_scatter_legend_artistr[s 3 > > ?C T*I B''(C(ggcggc2.@+AQ+FGH77;0@A77;2   H  *23D*EH& '*3H& ' 99  B /h //r+cfd}|S)Nc|jdd}|r||d<n ||d<d|d<tjjdi|S)Nr8rFrnone))rrrr)rLrNpatches Rectangle)rAr8fills r) legend_artistz/_get_patch_legend_artist..legend_artistusR&  #(K #(K #)K {{$$9S99r+r)rrs` r)_get_patch_legend_artistrss : r+)r6)NNN)NNTTFFNF)_Nr)TN)F)B__doc__rrrvri contextlibrurllib.requestrrtypesrnumpyrpandasr matplotlibrNmatplotlib.colorsrmatplotlib.pyplotpyplotrymatplotlib.cbookrseaborn._core.typingr seaborn.external.versionr seaborn.external.appdirsr __all__r\r r*r3rfr r rrrrrrrrrrrrsrwrrrrrrrrrrdboolrrrrr+r)rs$1 %/$-+,3 LQ%&&89<K\$N&"6 $&"K";@,1c*L`!F( -$iX0;"(4,: &-(2?55$7:777 00r+