L iF|ddlmZddlZddlZddlZddlZddl m Z ddl m Z ddlmZddlmZmZmZmZmZddlmZddlmZmZdd lmZmZdd lmZm Z gd Z!ee"d d Z#e"dTidddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4Z$ejJe d5eeee$ejLejN6Z(Gd7d8eZ)Gd9d:e)Z*Gd;dd?d@ddAd=dBddCdDddEdFZ,dGj[e#e(e dHe dIJe,_. dUdddddddddddd=ddCddKdLZ/dMj[e#e(e dHe dIJe/_. dUddddddddddddddddddddddCdNdOdddPdQZ0dRj[e#e(e dHSe0_.y)V)partialN)normalize_kwargs) VectorPlotter)adjust_legend_subtitles_default_color _deprecate_ci_get_transform_functions_scatter_legend_artist)groupby_apply_include_groups)EstimateAggregatorWeightedAggregator) FacetGrid _facet_docs)DocstringComponents _core_docs)relplot scatterplotlineplotaU The relationship between `x` and `y` can be shown for different subsets of the data using the `hue`, `size`, and `style` parameters. These parameters control what visual semantics are used to identify the different subsets. It is possible to show up to three dimensions independently by using all three semantic types, but this style of plot can be hard to interpret and is often ineffective. Using redundant semantics (i.e. both `hue` and `style` for the same variable) can be helpful for making graphics more accessible. See the :ref:`tutorial ` for more information. a The default treatment of the `hue` (and to a lesser extent, `size`) semantic, if present, depends on whether the variable is inferred to represent "numeric" or "categorical" data. In particular, numeric variables are represented with a sequential colormap by default, and the legend entries show regular "ticks" with values that may or may not exist in the data. This behavior can be controlled through various parameters, as described and illustrated below. )main_apirelational_semantic data_varsz x, y : names of variables in `data` or vector data Input data variables; must be numeric. Can pass data directly or reference columns in `data`. dataa{ data : DataFrame, array, or list of arrays Input data structure. If `x` and `y` are specified as names, this should be a "long-form" DataFrame containing those columns. Otherwise it is treated as "wide-form" data and grouping variables are ignored. See the examples for the various ways this parameter can be specified and the different effects of each. paletteaZ palette : string, list, dict, or matplotlib colormap An object that determines how colors are chosen when `hue` is used. It can be the name of a seaborn palette or matplotlib colormap, a list of colors (anything matplotlib understands), a dict mapping levels of the `hue` variable to colors, or a matplotlib colormap object. hue_orderz hue_order : list Specified order for the appearance of the `hue` variable levels, otherwise they are determined from the data. Not relevant when the `hue` variable is numeric. hue_normz hue_norm : tuple or :class:`matplotlib.colors.Normalize` object Normalization in data units for colormap applied to the `hue` variable when it is numeric. Not relevant if `hue` is categorical. sizesa sizes : list, dict, or tuple An object that determines how sizes are chosen when `size` is used. List or dict arguments should provide a size for each unique data value, which forces a categorical interpretation. The argument may also be a min, max tuple. size_orderz size_order : list Specified order for appearance of the `size` variable levels, otherwise they are determined from the data. Not relevant when the `size` variable is numeric. size_normz size_norm : tuple or Normalize object Normalization in data units for scaling plot objects when the `size` variable is numeric. dashesa dashes : boolean, list, or dictionary Object determining how to draw the lines for different levels of the `style` variable. Setting to `True` will use default dash codes, or you can pass a list of dash codes or a dictionary mapping levels of the `style` variable to dash codes. Setting to `False` will use solid lines for all subsets. Dashes are specified as in matplotlib: a tuple of `(segment, gap)` lengths, or an empty string to draw a solid line. markersa markers : boolean, list, or dictionary Object determining how to draw the markers for different levels of the `style` variable. Setting to `True` will use default markers, or you can pass a list of markers or a dictionary mapping levels of the `style` variable to markers. Setting to `False` will draw marker-less lines. Markers are specified as in matplotlib. style_orderz style_order : list Specified order for appearance of the `style` variable levels otherwise they are determined from the data. Not relevant when the `style` variable is numeric. unitsa: units : vector or key in `data` Grouping variable identifying sampling units. When used, a separate line will be drawn for each unit with appropriate semantics, but no legend entry will be added. Useful for showing distribution of experimental replicates when exact identities are not needed. estimatorz estimator : name of pandas method or callable or None Method for aggregating across multiple observations of the `y` variable at the same `x` level. If `None`, all observations will be drawn. ciz ci : int or "sd" or None Size of the confidence interval to draw when aggregating. .. deprecated:: 0.12.0 Use the new `errorbar` parameter for more flexibility. n_bootzY n_boot : int Number of bootstraps to use for computing the confidence interval. seedz seed : int, numpy.random.Generator, or numpy.random.RandomState Seed or random number generator for reproducible bootstrapping. legenda legend : "auto", "brief", "full", or False How to draw the legend. If "brief", numeric `hue` and `size` variables will be represented with a sample of evenly spaced values. If "full", every group will get an entry in the legend. If "auto", choose between brief or full representation based on number of levels. If `False`, no legend data is added and no legend is drawn. ax_inzb ax : matplotlib Axes Axes object to draw the plot onto, otherwise uses the current Axes. ax_outzS ax : matplotlib Axes Returns the Axes object with the plot drawn onto it. params)corefacetsrelstatceZdZdddddZdZy)_RelationalPlotterz@indexz@valuesz@columns)xyhuestyleTN)__name__ __module__ __qualname__wide_structuresortX/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/seaborn/relational.pyr1r1sIj:N Dr<r1c FeZdZgdZdidddddddddd fd ZdZxZS) _LinePlotter)color linewidthmarkerr NTr2 r variablesr$r&r'errorbarr:orient err_styleerr_kwsr(c tjdtjdz|_t |||||_||_||_ ||_ ||_ ||_ | |_ | in| |_| |_y)Ng?zlines.linewidthrrD)npr_mplrcParams_default_size_rangesuper__init__r$rEr&r'r:rFrGrHr() selfrrDr$r&r'rEr:rFrGrHr( __class__s r=rSz_LinePlotter.__init__s EE%L3<<(9: :   di8"      "$_r'  r<c  t|tjj}|j dd|j dd|j j }|jdk(r|j ddnB|jdk(rn2|j&d }t|j|jd |jv}|rtnt|j|j|j|j }|j"}|d vrd|d}t|ddd|}d} |j%| dD]\} } |j&r4d||g} | D cgc]} | |j(vs| }} | j+|} |j| |j-j/dkDrdd|j(vr d}t|| j1||j&}|j2||fit5dj7} n,t8j:| |d<t8j:| |d<dD]9} t=|| \}}| j?d| D]}|| || |<;d|j(vrEg}| j1dD].\}}|jA|jB|d|dfi|0n|jB| d| dfi|}|D]}d | vr#|jE|jG| d d!| vr#|jI|jK| d!d"| vsV|jM| d"}d#|vr|jO|d#d$|vs|jQ|d$jS}|jU}|jW}|j|j|jdk(r:|jX|jZd|}|| || |d| |dfd%|i||jdk(s|d&| || |dz | |d| |z fi}|j| d| dfi|d'||d(|}|j]D]8}t_|tj`jbs(|je|:|jg||jhr~tktjjgg)}d%d*d d}|jm|||||jo\} }| r(|ji|jp+}!ts|!y y y cc} w),z6Draw the plot onto an axes, passing matplotlib kwargs.markeredgewidthg?markeredgecolorwbandalphag?barsNz,`err_style` must be 'band' or 'bars', not {}weight)r&r'>r2r3z(`orient` must be either 'x' or 'y', not .r3r2r2r3r4sizer5T)from_comp_datar#rz,estimator must be None when specifying units)r:Fminmaxxy^)regexr4rar5r rBr@err) linestyler@r[xdataydatarAtitle):rrOlinesLine2D setdefaultrHcopyrG ValueErrorformat plot_datarr r$rEr&r'rF iter_datar:rD sort_values value_countsrdgroupbyapplyr reset_indexrMnanr filterextendplot set_color_hue_map set_linewidth _size_map _style_map set_dashes set_marker get_color get_alphaget_solid_capstyle fill_between fill_betweenx get_children isinstance collectionsLineCollection set_capstyle_add_axis_labelsr(radd_legend_dataget_legend_handles_labels legend_titler)"rTaxkwsrHrhweightedaggrFother grouping_varssub_varssub_data sort_varsvar sort_colsgrouped_invcolrp unit_dataline attributes line_color line_alpha line_capstylefunc error_paramebarsobj legend_artistattrshandlesr(s" r=rz_LinePlotter.plotssCII$4$45 ($/ (#.,,##% >>V #   w + ^^v %  ^^ '@CSZZ78 8t~~-EX!3E NNDMM$++DII    #H$NN4==%#ABX%&&t~~hv6F'GHh&!%'1B!CJ:- 8(<=:- 8(<= >)J)J 335M~~)dmm.G>>V+!#r7G7GHPD ( E7#/UG3-1H)-4 ^^v-!' $UOh%}.EE$wc]3huoE(#K (BKK  x}8C"$Jj"E %113<%c3??+I+IJ,,];!S[[445 ''*A ;;= NN; ,,a1,, DNN "  ! !$--U "< = T^^ #   T^^DL9 : dnn $9=gG#f-GAG   Q  c !$$&EbggbmmE2&>??I  ! !) ,(C  b! ;;#S4@E  %;S% H557JGQ):):;'/ Hs7L3rrs@r=rrs1#r$ D0r<rTmean)r%_ir2rZauto deprecated)r2r3r4rar5r#weightsrrrrrrr r!r"r$rEr&r'rFr:rGrHr(r%rc Xt||}t|t|||||||||||||||| }|j|| | |j | | | |j ||||t j}d|jvr)ddht|zs|t|trd n||d <|js|S|j||jd |jd d}t|j ||||d <|j!|||S) N)r2r3r4rar5r#r]rCrordernormrrrr!r rr5lsrjrir r@c)r r?dictmap_huemap_size map_stylepltgcarDsetrbool has_xy_data_attachpoprr)rr2r3r4rar5r#rrrrrrrr r!r"r$rEr&r'rFr:rGrHr(r%rkwargsrr@s r=rrs(Xr*H 1#DU7 F &Iw AIIgYXI>JJU*9J=KKkKB z WWYakk!4*=F *K!':fd3K2QWx == IIbM JJw 3 5 6E$RWWc5&AF7OFF2v Ir<a Draw a line plot with possibility of several semantic groupings. {narrative.main_api} {narrative.relational_semantic} By default, the plot aggregates over multiple `y` values at each value of `x` and shows an estimate of the central tendency and a confidence interval for that estimate. Parameters ---------- {params.core.data} {params.core.xy} hue : vector or key in `data` Grouping variable that will produce lines with different colors. Can be either categorical or numeric, although color mapping will behave differently in latter case. size : vector or key in `data` Grouping variable that will produce lines with different widths. Can be either categorical or numeric, although size mapping will behave differently in latter case. style : vector or key in `data` Grouping variable that will produce lines with different dashes and/or markers. Can have a numeric dtype but will always be treated as categorical. {params.rel.units} weights : vector or key in `data` Data values or column used to compute weighted estimation. Note that use of weights currently limits the choice of statistics to a 'mean' estimator and 'ci' errorbar. {params.core.palette} {params.core.hue_order} {params.core.hue_norm} {params.rel.sizes} {params.rel.size_order} {params.rel.size_norm} {params.rel.dashes} {params.rel.markers} {params.rel.style_order} {params.rel.estimator} {params.stat.errorbar} {params.rel.n_boot} {params.rel.seed} orient : "x" or "y" Dimension along which the data are sorted / aggregated. Equivalently, the "independent variable" of the resulting function. sort : boolean If True, the data will be sorted by the x and y variables, otherwise lines will connect points in the order they appear in the dataset. err_style : "band" or "bars" Whether to draw the confidence intervals with translucent error bands or discrete error bars. err_kws : dict of keyword arguments Additional parameters to control the aesthetics of the error bars. The kwargs are passed either to :meth:`matplotlib.axes.Axes.fill_between` or :meth:`matplotlib.axes.Axes.errorbar`, depending on `err_style`. {params.rel.legend} {params.rel.ci} {params.core.ax} kwargs : key, value mappings Other keyword arguments are passed down to :meth:`matplotlib.axes.Axes.plot`. Returns ------- {returns.ax} See Also -------- {seealso.scatterplot} {seealso.pointplot} Examples -------- .. include:: ../docstrings/lineplot.rst returnsseealso) narrativer+rr)r2r3r4rar5rrrrrrr!r"r(rc t|t||||||}|j||||j| | | |j | | |t j }|js|S|j||jdd}t|j||||d<|j|||S)Nr2r3r4rar5rrr)r!rr@) rrrrrrrrrrrrr)rr2r3r4rar5rrrrrrr!r"r(rrrr@s r=rr^s  aSt5A A IIgYXI>JJU*9J=KK{K3 z WWY == IIbM JJw %E$RZZeVDF7OFF2v Ir<aDraw a scatter plot with possibility of several semantic groupings. {narrative.main_api} {narrative.relational_semantic} Parameters ---------- {params.core.data} {params.core.xy} hue : vector or key in `data` Grouping variable that will produce points with different colors. Can be either categorical or numeric, although color mapping will behave differently in latter case. size : vector or key in `data` Grouping variable that will produce points with different sizes. Can be either categorical or numeric, although size mapping will behave differently in latter case. style : vector or key in `data` Grouping variable that will produce points with different markers. Can have a numeric dtype but will always be treated as categorical. {params.core.palette} {params.core.hue_order} {params.core.hue_norm} {params.rel.sizes} {params.rel.size_order} {params.rel.size_norm} {params.rel.markers} {params.rel.style_order} {params.rel.legend} {params.core.ax} kwargs : key, value mappings Other keyword arguments are passed down to :meth:`matplotlib.axes.Axes.scatter`. Returns ------- {returns.ax} See Also -------- {seealso.lineplot} {seealso.stripplot} {seealso.swarmplot} Examples -------- .. include:: ../docstrings/scatterplot.rst r)r2r3r4rar5r#rrowrcol_wrap row_order col_orderrrrrrrr!r r"r(kindheightaspect facet_kwsc 0 |dk(rt}t}|dn|}n)|dk(rt}t}|dn|}nd|d}t |d|vr?dj |dz}t j|t|jdt||||| } |dk(r || d <|| d <n6|d }t j|d |d}t j|d ||| |}!|!j| |||!j||||!j|||d|!jvrC|!jj } |!jj"}|!jj$}ndx} x}}d|!jvrB|!j&j }|!j&j"}|!j&j$}d|!jvra|!j(j"}|r!|D"cic]}"|"|!j)|"d}}"nd}|r!|D"cic]}"|"|!j)|"d}}"n d}ndx}x}}|!j} |!j*}#t| ||||||||d }$|$j-||dk(r|$jdt|||| |||}%|dk(r|%j-|||!j/||%| D&cic]}&|&d|& }'}&d |'vr|'jd |'d<|$j-|'dD]4}(|(|!jvs|!j|("d|(d|!j|(<6dD&cic]}&|&|!jj1|& })}&|'j3}*|*j-|)|!j*j5|* }+|in|j3}t7d4d!|+j9d"d#$i|)| | | ||dd%|},|,j:|fi|$|,j=| j1d&xsd'| j1d(xsd'|r|#|!_gd)}-|dk(rt>}.|-gd*z }-n-tAtBjDjFgg+}.|-gd,z }-|jID"&cic] \}"}&|"|-vs |"|&}/}"}&d-dd.}0|dk(rd/|0d<n |dk(rd0|0d<|!jK|,jLjNd1|.|/|0|!jPr3|,jS|!jP|!jT|!jVd2| jID"&cic]\}"}&d|"|&d|"dn|&}1}"}&|,jXj5|1 }2|y||ut[|t\j^st]j^|}t]j`||2|2jbje|jbdd3|,_,|,S|2|,_,|,Scc}"wcc}"wcc}&wcc}&wcc}&}"wcc}&}"w)5NrTrz Plot kind z not recognizedrzarelplot is a figure-level function and does not accept the `ax` parameter. You may wish to try {}rrr#r]z8The `units` parameter has no effect with kind='scatter'.rK) stacklevelz:The `weights` parameter has no effect with kind='scatter'.rrrrr4rar5rBr F) rrrrrrr!r r"r()r2r3rrr4rar5)r#rrr)rr)columnsrrall)axishow)rrrrrrr2rir3)rr@r[rrB)r facecolorfcrecrAlwrk) markersizemsrWmewrXmecrjrrAr r@)r4r5rrAr) legend_data label_orderroadjust_subtitles) left_index right_indexr;)3rrr?rrtruwarningswarn UserWarningrrrrrrDr lookup_tablerrrrrvupdateassign_variablesrrsrenamerr map_dataframeset_axis_labelsr rrOrprqitemsraxesflatr add_legend legend_orderrrrpd DataFramemerger difference)3rr2r3r4rar5r#rrrrrrrrrrrrr!r r"r(rrrrrPlotterrrhmsgrDrkrvplot_kwsgrid_variablesvplot_variablesrgrid_kwsnew_cols full_datagkeysr common_kwsr orig_cols grid_datas3 r=rrsK y!!/$w V4&0o v~ 99?v 9N   c;' 4qA3T?I v~" '% (  LC MM#! ,  NC MM#! ,  A IIgYXI>JJU*9J=KKkKB  **))JJ%% ::??)---)h  (([['' KK$$ !++ll)) =HIq!,,q(33IGIG !$2$6$6x$@y! OON#* !++ !++c"2":!"3%qzAKK *0>>!1;;??1%%>H>""$H OOH ""8"4I 'Y^^-=I    1%  0   Y)fU     AAOOD%H%immC(.B c0B0HbI   6 9 2M R RD#CII$4$4BbIM  D(.||~Ctq!dadC C$/ 9 E&M V^'E&M !&&++a.-UK == LLQ]]%&^^ ~~*.  0;D//:K26!Q!A3QY1QCqA-I i 0I Q]am$ -<<%D  i''224<<@ A   H H}JI@5?`Ds*3W8W= X#X X X =Xa Figure-level interface for drawing relational plots onto a FacetGrid. This function provides access to several different axes-level functions that show the relationship between two variables with semantic mappings of subsets. The `kind` parameter selects the underlying axes-level function to use: - :func:`scatterplot` (with `kind="scatter"`; the default) - :func:`lineplot` (with `kind="line"`) Extra keyword arguments are passed to the underlying function, so you should refer to the documentation for each to see kind-specific options. {narrative.main_api} {narrative.relational_semantic} After plotting, the :class:`FacetGrid` with the plot is returned and can be used directly to tweak supporting plot details or add other layers. Parameters ---------- {params.core.data} {params.core.xy} hue : vector or key in `data` Grouping variable that will produce elements with different colors. Can be either categorical or numeric, although color mapping will behave differently in latter case. size : vector or key in `data` Grouping variable that will produce elements with different sizes. Can be either categorical or numeric, although size mapping will behave differently in latter case. style : vector or key in `data` Grouping variable that will produce elements with different styles. Can have a numeric dtype but will always be treated as categorical. {params.rel.units} weights : vector or key in `data` Data values or column used to compute weighted estimation. Note that use of weights currently limits the choice of statistics to a 'mean' estimator and 'ci' errorbar. {params.facets.rowcol} {params.facets.col_wrap} row_order, col_order : lists of strings Order to organize the rows and/or columns of the grid in, otherwise the orders are inferred from the data objects. {params.core.palette} {params.core.hue_order} {params.core.hue_norm} {params.rel.sizes} {params.rel.size_order} {params.rel.size_norm} {params.rel.style_order} {params.rel.dashes} {params.rel.markers} {params.rel.legend} kind : string Kind of plot to draw, corresponding to a seaborn relational plot. Options are `"scatter"` or `"line"`. {params.facets.height} {params.facets.aspect} facet_kws : dict Dictionary of other keyword arguments to pass to :class:`FacetGrid`. kwargs : key, value pairings Other keyword arguments are passed through to the underlying plotting function. Returns ------- {returns.facetgrid} Examples -------- .. include:: ../docstrings/relplot.rst )rr+rr;)N)1 functoolsrrnumpyrMpandasr# matplotlibrOmatplotlib.pyplotpyplotrmatplotlib.cbookr_baserutilsrrr r r _compatr _statisticsr raxisgridrr _docstringsrr__all__r_relational_narrative_relational_docsfrom_nested_componentsfrom_function_paramsrS _param_docsr1r?rrru__doc__rrr;r<r=rJs2-2?,8 1,D !-6yy y  !y./y:;yD EyRSy^_yh iyz {yJKyV Wydeypqy@ AyH IyP Qy` ayh iyx9!88 H  { +,- 1  1 12D2M2M N  v0%v0rU0(U0r - d4t4 D4 44 4z$T TVT lt-`O^ F#  y ! y !  _ p   d4t D4 44 d6d F3f F#  y ! y !  g x G  d4t4 $ D4 44 4  !AG TLX F#  y ! Yr<