a
    Sic9                     @   s  d dl Z d dlZd dlZd dlZd dlmZ	 ddl
mZ ddlmZmZmZmZ ddlmZ ddlmZmZ ddlmZmZ g dZeed	d
dZeddddddddddddddddddddZejed  eeeeeejd!Z G d"d# d#eZ!G d$d% d%e!Z"G d&d' d'e!Z#dAddddddddddddd(ddd)d*d+dd,d(d-dd.d/dd0d1d2Z$d3j%ee ed4 ed5 d6e$_&dBdddddddddddd(dd.dd7d8d9Z'd:j%ee ed4 ed5 d6e'_&dCddddddddddddddddddddd.d;d<ddd=d>d?Z(d@j%ee ed4 ed5 d6e(_&dS )D    N   )VectorPlotter)locator_to_legend_entriesadjust_legend_subtitles_default_color_deprecate_ci)EstimateAggregator)	FacetGrid_facet_docs)DocstringComponents
_core_docs)relplotscatterplotlineplotaU  
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 <relational_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.
    )Zmain_apiZrelational_semanticz
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`.
    a{  
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.
    aZ  
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.
    z
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.
    z
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.
    a  
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.
    z
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.
    z
size_norm : tuple or Normalize object
    Normalization in data units for scaling plot objects when the
    `size` variable is numeric.
    a  
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.
    a  
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.
    z
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.
    a:  
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.
    z
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.
    z
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.

    zY
n_boot : int
    Number of bootstraps to use for computing the confidence interval.
    z
seed : int, numpy.random.Generator, or numpy.random.RandomState
    Seed or random number generator for reproducible bootstrapping.
    a  
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.
    zb
ax : matplotlib Axes
    Axes object to draw the plot onto, otherwise uses the current Axes.
    zS
ax : matplotlib Axes
    Returns the Axes object with the plot drawn onto it.
    )Z	data_varsdatapalette	hue_orderhue_normsizes
size_order	size_normdashesmarkersstyle_orderunits	estimatorcin_bootseedlegendZax_inZax_outparams)coreZfacetsrelstatc                   @   s&   e Zd ZdddddZdZdd ZdS )	_RelationalPlotterz@indexz@valuesz@columns)xyhuestyleTc               	      s\  j }t|tr&|dvr&d}t|n|du r2d}i g  dd fddd	D D }t|d
krl| }nd}tddddddd} fdd}d}jjdko|dkp|dkotjj	|k}	|	r.tjj
tjjrtjj|d}
ntjj|d}
tjj	tjj	f}t|
|jd  j\}}n$jj	du rFg  }}njj	 }}|sjdddur|jd dfjd fi | t||D ]2\}}|dur|}|jd ||d qjjdko|dkp|dkotjj	|k}|rltjj
tjjr(tjj|d}
ntjj|d}
tjj	tjj	f}t|
|jd  j\}}n$jj	du rg  }}njj	 }}|s̈jdddur|jd dfjd fi | t||D ]4\}}|durֈ|}|jd |||d q|sHjdddurH|jd dfjd fi | jj	durjj	D ]@}|dur^|}|jd ||dd|ddd  q^t|j}i }g } D ]}|\}}| }|d!d" i }jd#g D ]}||v r|| ||< q|g g fd$|i|}jd%kr0|d }|||< | | q|_!|_"|_#dS )&z>Add labeled artists to represent the different plot semantics.)autobrieffullz7`legend` must be 'auto', 'brief', 'full', or a boolean.Tr)   c                 S   s   h | ]}|d ur|qS N ).0titler-   r-   N/var/www/html/django/DPS/env/lib/python3.9/site-packages/seaborn/relational.py	<setcomp>   s   z5_RelationalPlotter.add_legend_data.<locals>.<setcomp>c                 3   s   | ]} j |d V  qd S r,   	variablesgetr.   vselfr-   r0   	<genexpr>       z5_RelationalPlotter.add_legend_data.<locals>.<genexpr>r'   sizer(   r    Fwr   )visiblecolors	linewidthmarkerr   c                    sF   | |f}|v r&| j f i | n | tf i ||< d S r,   )updateappenddict)var_nameval_namekwskey)keyslegend_kwargsr-   r0   rD      s
    
z2_RelationalPlotter.add_legend_data.<locals>.update   numericr*   )numticks)nbinsr'   Nr/   )r@   r<   )rB   rA   r(   rC   r   )rC   r   r@   z.2r?   labelplot)$r   
isinstancestr
ValueErrorlenpoprF   _hue_mapZmap_typelevelsnormmplcolorsLogNormticker
LogLocatorMaxNLocatorminmaxr   	plot_datainfer_objectsdtyper3   r4   zip	_size_map
_style_mapgetattr_legend_func
setdefault_legend_attributesrE   legend_titlelegend_datalegend_order) r8   ax	verbosityerrtitlesrm   Z	title_kwsrD   Zbrief_ticksZ	brief_huelocatorlimitsZ
hue_levelsZhue_formatted_levelslevelZformatted_levelr@   Z
brief_sizeZsize_levelsZsize_formatted_levelsr<   attrsfuncrn   ro   rJ   _rQ   rI   Zuse_kwsattrartistr-   )rK   rL   r8   r0   add_legend_data   s    


















z"_RelationalPlotter.add_legend_dataN)__name__
__module____qualname__Zwide_structuresortr|   r-   r-   r-   r0   r$      s   r$   c                       sJ   e Zd Zg dZdZdi dddddddddd fdd
Zd	d
 Z  ZS )_LinePlotter)r@   rB   rC   r   rR   NTr%   r   r3   r   r   r   errorbarr   orient	err_styleerr_kwsr   c                   sl   t jd tjd  | _t j||d || _|| _|| _	|| _
|| _|| _|	| _|
d u r\i n|
| _|| _d S )Ng      ?   zlines.linewidthr   r3   )npr_r[   rcParams_default_size_rangesuper__init__r   r   r   r   r   r   r   r   r   )r8   r   r3   r   r   r   r   r   r   r   r   r   	__class__r-   r0   r   _  s    z_LinePlotter.__init__c                    s  | d|dd | d|dd  j } jdkrJ| dd	 n* jd
krVn jdurtd}t| jt j j	 j
 jd} j}|dvrd|d}t|ddd| }d} j|ddD ] \}	}
 jrd||g} fdd|D }|
|}
 jdurb|
|   dkrbd jv r@d}t||
j| jd}||| }
n tj|
| d< tj|
| d< dD ]@} |r|
jd | d!D ]}td"|
| |
|< qqd jv rg }|
dD ],\}}||j|d |d fi | qn|j|
d |
d fi |}|D ]}d#|	v rT| |	d#  d$|	v rr|  |	d$  d%|	v r2 !|	d% }d&|v r|"|d&  d'|v r2|#|d'  q2|$ }|% }|& } jdurΈ j	durΈ jdkr:|j'|j(d| }||
| |
| d |
| d fd(|i| qΈ jd
kr| d)|
| |
| d  |
| d |
|  fi}|j	|
d |
d fi |d*||d+|}|) D ] }t*|t+j,j-r|.| qqΈ /|  j0r 1| |2 \}}|r|j0 j3d,}t4| dS )-z6Draw the plot onto an axes, passing matplotlib kwargs.markeredgewidthmewg      ?markeredgecolormecr>   bandalphag?barsNz,`err_style` must be 'band' or 'bars', not {})r   r   >   r&   r%   z(`orient` must be either 'x' or 'y', not .r&   r%   r%   r&   r;   T)Zfrom_comp_datar   c                    s   g | ]}| j v r|qS r-   )r3   )r.   varr7   r-   r0   
<listcomp>  r:   z%_LinePlotter.plot.<locals>.<listcomp>r   z,estimator must be None when specifying units)r   ra   rb   xy^)regex
   r'   r<   r(   r   rC   r@   rr   r=   )	linestyler@   r   r/   )5rk   rW   r   copyr   rU   formatr   r   r   r   r   r   Z	iter_datar   sort_valuesvalue_countsrb   r3   groupbyapplyreset_indexr   nanZ_log_scaledfilterpowerextendrR   	set_colorrX   set_linewidthrg   rh   
set_dashes
set_marker	get_color	get_alphaget_solid_capstylefill_betweenfill_betweenxget_childrenrS   r[   collectionsLineCollectionset_capstyle_add_axis_labelsr   r|   get_legend_handles_labelsrm   r   )r8   rp   rI   r   rr   aggr   otherZgrouping_varsZsub_varsZsub_dataZ	sort_varsZ	sort_colsgroupedr   collinesry   Z	unit_dataline
attributesZ
line_colorZ
line_alphaZline_capstylerx   Zerror_paramZebarsobjhandlesr   r-   r7   r0   rR   z  s    



	

(







z_LinePlotter.plotr}   r~   r   rl   rj   r   rR   __classcell__r-   r-   r   r0   r   Z  s   
r   c                       s:   e Zd Zg dZdZdi dd fdd
Zdd Z  ZS )	_ScatterPlotter)r@   rA   rC   scatterNr   r3   r   c                   s6   t jd t tjd  | _t j||d || _d S )Nr   zlines.markersizer   )	r   r   squarer[   r   r   r   r   r   )r8   r   r3   r   r   r-   r0   r     s    z_ScatterPlotter.__init__c              	      s   j  }|jrd S tt|tj}|d|}|d|}d jv rl j	j
d } 	|d}|d| |dtjdd}	t|	tjjstj|	}	|	 r|dd |jf ||d	|}
d
 jv r|
 |d
  d jv r|
 |d  d jv r0 fdd|d D }|
| d|vr^|
 }|
dtt|d   |  jr | | \}}|r|j j d}t!| d S )Nr%   r&   r(   r   rC   o	edgecolorr>   r   r'   r<   c                    s   g | ]}  |d qS )pathrh   )r.   valr7   r-   r0   r   H  r:   z(_ScatterPlotter.plot.<locals>.<listcomp>rB   g{Gz?r   r   )"rc   dropnaemptyr   r+   rV   r   r4   r3   rh   rY   rk   r[   r   rS   r   MarkerStyle	is_filledr   set_facecolorsrX   	set_sizesrg   	set_paths	get_sizesset_linewidthssqrt
percentiler   r   r|   r   rm   r   )r8   rp   rI   r   r   r%   r&   Zexample_levelZexample_markermpointspr   r   ry   r   r-   r7   r0   rR     sB    






z_ScatterPlotter.plotr   r-   r-   r   r0   r     s   r   Tmean)r   _   i  r%   r   r)   
deprecated)r%   r&   r'   r<   r(   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rp   c                K   s   t ||}tt }t| ||||||||||d}|j|||	d |j|
||d |j|||d |d u rtt }|d u rddht	|@ s|d u st
|trdn||d< |js|S || |d	|d
d }t|j||||d	< ||| |S )Nr   r   orderrZ   r   r   rZ   r   r   r   lsr   r=   r   r@   c)r   r   get_semanticslocalsmap_huemap_size	map_stylepltgcasetrS   boolhas_xy_data_attachrW   r   rR   )r   r%   r&   r'   r<   r(   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rp   kwargsr3   r   r@   r-   r-   r0   r   [  s,    

r   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}
{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

returnsseealso)Z	narrativer    r   r   )r%   r&   r'   r<   r(   r   r   r   r   r   r   r   r   r   rp   c                K   s   t t }t | ||d}|j|||d |j|	|
|d |j||d |d u rXt }|jsb|S |	| |
dd }t|j||||d< ||| |S )Nr   r   r   )r   r   r@   )r   r   r   r   r   r   r   r   r   r   rW   r   r   rR   )r   r%   r&   r'   r<   r(   r   r   r   r   r   r   r   r   r   rp   r   r3   r   r@   r-   r-   r0   r     s    	
r   a  Draw 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      )r%   r&   r'   r<   r(   r   rowr   col_wrap	row_order	col_orderr   r   r   r   r   r   r   r   r   r   kindheightaspect	facet_kwsc          ,         s  |dkr"t }t}|d u rdn|}n6|dkrDt}t}|d u r>dn|}nd| d}t|d|v rd|d }t|t |	d || |
t |d	  j|||d
  j|||d  j|||d d jv r jj} jj} jj}nd  } }}d jv r jj} jj} jj}d jv rp jj}|rL fdd|D }nd }|rj fdd|D }nd }nd  } }} j} j}  j}!t|||||||||dd
}"|"| |dkr|"	d d}#|!|#  _ j| t||||||||dd dd |D }$|"|$ dD ]4}%|% jv r j|% d u rd|% d j|%< q fdd|#D }&|$ }'|'|&  jj|'d}(|d u ri n| }tf d|(jddd i|&|	|
|||dd!|})|)j|fi |" |)j |!d"|!d#d$ |r.|  _ "|)j#j$d%   j%r.|)j& j% j' j(dd& d'd |) D }*|)j*j|*d}+| d ur|d usl|d urt+| t,j-st,-| } t,j.| |+|+j/0| j/ ddd(|)_*n|+|)_*|)S ))Nr   Tr   z
Plot kind z not recognizedrp   zarelplot is a figure-level function and does not accept the `ax` parameter. You may wish to try {}rR   r   r   r   r   r'   r<   r(   c                    s   i | ]}|  |d qS )rC   r   r.   kr   r-   r0   
<dictcomp>w  r:   zrelplot.<locals>.<dictcomp>c                    s   i | ]}|  |d qS )r   r   r   r  r-   r0   r  {  r:   F)
r   r   r   r   r   r   r   r   r   r   r   )r   r   )r%   r&   r'   r<   r(   r   r   r   r   c                 S   s   i | ]}|d | qS )ry   r-   r5   r-   r-   r0   r    r:   ry   c                    s   i | ]}| j |qS r-   r2   r5   r  r-   r0   r    r:   )columnsr   r   all)axishow)r   r   r   r   r   r   r%   r&   )xlabelylabelr   )rn   Zlabel_orderr/   Zadjust_subtitlesc                 S   s0   i | ](\}}d | |du r(d | d n|qS )ry   Nr-   )r.   r   r6   r-   r-   r0   r    s   )
left_indexright_index)1r   r   r   r   rU   r   warningswarnUserWarningrW   r   r   r   r   r   r3   rX   lookup_tablerY   rZ   rg   rh   rc   Z	semanticsrF   rD   Zassign_variablesr   renamer	   r   Zmap_dataframer   r4   r|   axesflatrn   
add_legendro   rm   itemsr   rS   pd	DataFramemerger  
difference),r   r%   r&   r'   r<   r(   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Zplotterrx   rr   msgr3   rc   Zplot_semanticsplot_kwsZgrid_semanticsZplot_variablesr   Zgrid_kwsnew_colsZ	full_datagZ	orig_colsZ	grid_datar-   r  r0   r   9  s    









	

r   a	  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}
{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

)N)N)N))r  numpyr   pandasr  
matplotlibr[   matplotlib.pyplotpyplotr   Z_oldcorer   utilsr   r   r   r   Z_statisticsr   axisgridr	   r
   Z_docstringsr   r   __all__rF   Z_relational_narrativeZ_relational_docsZfrom_nested_componentsZfrom_function_paramsr   Z_param_docsr$   r   r   r   r   __doc__r   r   r-   r-   r-   r0   <module>   s   	|
 # 3P .LT 
"4< 

 )I