a
    SicT                 "   @   s,  d Z ddlmZ ddlmZ ddlZddlZ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 ddlmZ ddlmZ dd	l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%m&Z&m'Z'm(Z(m)Z) ddl*m+Z+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1m2Z2 g dZ3e4dddddddZ5e1j6e2d e1e"e1e5e17ej8e17ej8e17ej8dZ9G dd deZ:G dd de:Z;dId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ddd"dd% d&d'Z<d(j=e9e2d) e2d* d+e<_ dJdddddddddd#d"d!d!d,dd"dd-d.d/d0dd"d!dddd1d2d3Z>d4j=e9e2d) e2d* d+e>_ dKddddd5d!ddddd"dd6d7d8Z?d9j=e9e2d) e2d* d+e?_ dLdddd:d"dddd"dd;
d<d=Z@d>j=e9e2d) e2d* d+e@_ dMddddddd?d!ddd"dddddddd@dddAdBdCZAdDj=e9e2d) e2d* d+eA_ dEdF ZBdNdGdHZCdS )Oz1Plotting functions for visualizing distributions.    )Number)partialN)to_rgba)LineCollection   )VectorPlotter)ECDF	HistogramKDE)Hist)	FacetGrid_facet_docs)	remove_na_kde_support_normalize_kwargs_check_argument_assign_default_kwargs_default_color)color_palette)husl)gaussian_kde)DocstringComponents
_core_docs)displothistplotkdeplotecdfplotrugplotdistplotz
multiple : {{"layer", "stack", "fill"}}
    Method for drawing multiple elements when semantic mapping creates subsets.
    Only relevant with univariate data.
    ao  
log_scale : bool or number, or pair of bools or numbers
    Set axis scale(s) to log. A single value sets the data axis for univariate
    distributions and both axes for bivariate distributions. A pair of values
    sets each axis independently. Numeric values are interpreted as the desired
    base (default 10). If `False`, defer to the existing Axes scale.
    zM
legend : bool
    If False, suppress the legend for semantic variables.
    z
cbar : bool
    If True, add a colorbar to annotate the color mapping in a bivariate plot.
    Note: Does not currently support plots with a ``hue`` variable well.
    zU
cbar_ax : :class:`matplotlib.axes.Axes`
    Pre-existing axes for the colorbar.
    zd
cbar_kws : dict
    Additional parameters passed to :meth:`matplotlib.figure.Figure.colorbar`.
    )multiple	log_scalelegendcbarcbar_axcbar_kwsparams)corefacetsdistkdehistecdfc                       s   e Zd ZdZdddZddiZdi f fdd	Zed	d
 Zedd Z	edd Z
dd Zdd Zdd Zdd Zdd Zdd Zd,ddZdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Z  ZS )-_DistributionPlotter)xyhueweightsz@valuesz@columns)r-   r/   r-   Nc                    s   t  j||d d S )Ndata	variables)super__init__)selfr2   r3   	__class__ Q/var/www/html/django/DPS/env/lib/python3.9/site-packages/seaborn/distributions.pyr5   k   s    z_DistributionPlotter.__init__c                 C   s   t ddht| j S )z$Return True if only x or y are used.r-   r.   boolsetr3   r6   r9   r9   r:   
univariates   s    z_DistributionPlotter.univariatec                 C   s"   | j stdddh| j S )z3Return the variable with data for univariate plots.zThis is not a univariate plotr-   r.   )r?   AttributeErrorintersectionr3   popr>   r9   r9   r:   data_variable|   s    z"_DistributionPlotter.data_variablec                 C   s   t ddht| j@ S )z.Return True at least one of x or y is defined.r-   r.   r;   r>   r9   r9   r:   has_xy_data   s    z _DistributionPlotter.has_xy_datac	              	   C   s   g }	g }
| j jD ]T}|  |}| ||||||}d|v rF|dd |	|f i | |
| qt|tjjr|j	|	|
fd| j
d i| n2tt|
|	}|j|f| j
d | jd d| dS )zDAdd artists that reflect semantic mappings and put then in a legend.	facecolorcolorNtitler/   )rG   label_order)_hue_maplevels_artist_kwsrB   append
isinstancemplaxesAxesr!   r3   dictzip
add_legend
var_levels)r6   ax_objartistfillelementr   alpha
artist_kws
legend_kwshandleslabelslevelrF   kwslegend_datar9   r9   r:   _add_legend   s,    
 z _DistributionPlotter._add_legendc                 C   s   |  }|rtt|tjj}|dt|| |dkr<d|d< |dv sL|dkr`|dtjd  q|dt|d n.|dkrd|d< t|||d< nt|||d< |S )	z<Handle differences between artists in filled/unfilled plots.rE   barsnonerF   stackrW   	edgecolorzpatch.edgecolorr   )copyr   rN   collectionsPolyCollection
setdefaultr   rcParams)r6   r_   rW   rX   r   rF   rY   r9   r9   r:   rK      s    z _DistributionPlotter._artist_kwsc           	      C   s^   t |}t |}t |ddd }t ||  }t |d| }t j||dd}|S )z:Return data levels corresponding to quantile cuts of mass.Nr   clip)mode)npasarrayravelsortcumsumsumsearchsortedtake)	r6   r2   quantileZisopropvaluessorted_valuesnormalized_valuesidxrJ   r9   r9   r:   _quantile_to_level   s    

z'_DistributionPlotter._quantile_to_levelc                 C   s   t |\}}}}t|||\}}}tddtddd }td}	||	dddf< |t| |	dddf< tdd	d|	ddd
f< tdd |	D dd}
t	j
|
ddd S )z0Return a sequential colormap given a color seed.rl   r   gffffffr@N   )r}      r   #   P      c                 S   s   g | ]}t j| qS r9   )r   husl_to_rgb).0hslr9   r9   r:   
<listcomp>       z9_DistributionPlotter._cmap_from_color.<locals>.<listcomp>)r   r   rgb_to_huslro   linspaceintzeroscosrm   rN   colorsListedColormap)r6   rF   rgb_hsxxZrampr   r9   r9   r:   _cmap_from_color   s    
z%_DistributionPlotter._cmap_from_colorc                 C   s@   | j r| j| j dk}n$| jd dk}| jd dk}||f}|S )zHFind default values for discrete hist estimation based on variable type.categoricalr-   r.   )r?   	var_typesrC   )r6   discreteZ
discrete_xZ
discrete_yr9   r9   r:   _default_discrete   s    z&_DistributionPlotter._default_discretec                 C   s.  dd |  D }d| jvr$||fS |dv rt|jdddddf }i }ttt|jD ]:\}}|	dd|	ddf}|
|g  || | q`| }| D ]l}|j| }	||	 jd	d
}
||	 jd	d
||	< |dkr||	 j|
dd
||	< ||	 jddd
d||	< q|dkr&| jd }t|}|D ]}t|d }|| jdd}||}| | jrt|d }t|d |d  }|| | }td|||  }td||d |  }|| |d< ||d< n(|d  |  < |d  ||d  7  < |ddgd ||< q:||fS )z?Modify the density data structure to handle multiple densities.c                 S   s   i | ]\}}|t |qS r9   )ro   
zeros_liker   kvr9   r9   r:   
<dictcomp>   r   z:_DistributionPlotter._resolve_multiple.<locals>.<dictcomp>r/   rd   Nrl   colrowcolumnsaxisrW   indexr   r   dodgeheightsnameedgeswidths
   )itemsr3   pd	DataFrameiloc	enumeratemaprQ   r   getrj   rL   rg   rx   rt   rs   divshiftfillnarT   lenreset_indexr   _log_scaledrC   ro   log10power	set_index)r6   curvesr   	baselinesZcolumn_groupsiZkeydZ	facet_keyZcol_idxscolsZnorm_constant
hue_levelsnkeyr^   r*   Z	level_idxZlog_minZlog_maxZ	log_widthnew_minnew_maxr9   r9   r:   _resolve_multiple   sJ    






z&_DistributionPlotter._resolve_multipleTc              	   C   s|  t f i |}t| jddh r>|rB| j }|||  nd}| j }	|rfd|	v rf|	d  }
nt|	}
i }| j	dddD ]\}}|| }d| jv r|d }| }nd }t|}t
| }t|dk pt|d	}z|s|||d
\}}W n t
jjy   d}Y n0 |r4d}|rtj|tdd q|rFt
d|}|rX|||
 9 }t| }tj||d||< q|S )Nr-   r.   Fr0   r/   Tfrom_comp_datar   r   r0   zfDataset has 0 variance; skipping density estimate. Pass `warn_singular=False` to disable this warning.   
stacklevelr   )r   )r
   r=   r3   	comp_datadropnadefine_support	plot_datart   r   	iter_dataro   
nan_to_numvarmathiscloselinalgLinAlgErrorwarningswarnUserWarningr   tupler   r   Series)r6   rC   common_normcommon_gridestimate_kwsr    warn_singular	estimatorZall_observationsall_datawhole_weight	densitiessub_varssub_dataobservationsr0   part_weightvariancesingulardensitysupportmsgr   r9   r9   r:   _compute_univariate_density-  sL    




z0_DistributionPlotter._compute_univariate_densityc           O   
   K   s	  |d u ri n|  }|d u r i n|  }|d u r4i n|  }tdg d| tdg d| d| jv o|d dko|d d u o|d	  }|rd
}t|t d|d< |d dkrd}| j}tf i |}i }| j	 }|
dd }t| jddh }|r|r|||d }nd}|r.|d ur.| }nt|}|rx|dd |d |d< | | j}| j| j||||dd}| jdddD ]\}}t| }| j}d| jv r|d|d< |d  }nt|}|r|s|||d }|||||}||j  }|d  } ||  | d  }!| | jrdtd|!|  td|! } td|!}!|r||v r|| }"|jr| }#n||   }#||  |#9  < |!d| d |   }!| |9 } tj tj!|!ddtj!| ddg}$tj"||$dd }%|r|%|| 9 }%|%||< q| #||\}}&|rL| #||d!krBd n|\}}'|d"krZd#ndtj$f}(|d"kr|j%& })|)d }!|)d } |!' |! | j(|!)   f}*ng }*|rd| jv r|d$kr|d%krd&nd'}+n|rd&}+nd(}+nd}+|d)|+},g }-| jddd*D ]d\}}'t| }|| *d+ }%t,|&| }.| -|}/d| jv rl| .|d }0n|	}0| /|||||0|,}1|d%kr8| jdkr|/j0n|/j1}2|2|%d |%d |. |%d |.fd+d,i|1}3|3D ]T}4| jdkr|*|4j2j3d d < |(|4j2j4d d < n |(|4j2j3d d < |*|4j2j4d d < q|-5|3 nv|d-kr|%j6d. }5t7|%d |5d |5d  }6t7|%d |5d }7t7|.|.d. }8| jdkrd/}9d0}:nd/}9d1}:n2|d2kr|%d |%d d  }6|%d }7|.}8d }9d }:| jdkrH|r|/j8|6|8|7fd-|9i|1};n|/j9|6|7fd3|:i|1\};|*|;j2j3d d < |(|;j2j4d d < n\|rj|/j:|6|8|7fd-|9i|1};n|/j9|7|6fd3|:i|1\};|(|;j2j3d d < |*|;j2j4d d < |-7|; |rz|| }"W n t;y   Y qY n0 |"j%}<d| jv r|<|"f}=d dtj$f }>}?n|"|<f}=dtj$fd  }>}?t<|0d|d4< |/j9|=i |\}@|>d urZ|>|@j2j3d d < |?d ur|?|@j2j4d d < q|d%krd5|vrt=d6d7 | D j+dd8}A|Ad > }B|Aj(|Bdf }C|Aj(|Bdf }Dt?j$}E|  D ]|\}}'| -|}/|/@  d9|/jAjB tC|/jDE|D|C gd |/jDE|Dgd   \}F}G| jdkrJ|F}Hn|G}Ht'd:|H |E}Eq|-D ]D}4|4F }I|s~|Id;9 }It'|E|I}J|sd&}Kt|J|K}J|4G|J qd| jHd ur| jHn| jIjJjKd }/d< }L}M| jdkr|jL }M| jdkr|jL }L| M|/|L|M d| jv 	r||
	r||	s.|d%k	r<tNtOjPjQ};ntNtOjRjSg g };| jHd u	r^| jHn| jI}N| T|N|;||||,|i  d S )=Nr   )layerre   rW   r   rX   )rb   steppolyr0   binsautobinwidthr   zb`bins` cannot be 'auto' when using weights. Setting `bins=10`, but you will likely want to adjust.r   statcountFr-   r.   cutr   
cumulative)r   r/   Tr   weightspacer   r   r   r   r   r   )r   r   r   rW   r   r   r   rb   g      ?      ?      ?rY   reversealignedger   rl   post
steps-post	steps-prer   	drawstylerF   	linewidthc                 S   s   g | ]\}}|j  qS r9   )r   to_frame)r   r   r   r9   r9   r:   r     s   zB_DistributionPlotter.plot_univariate_histogram.<locals>.<listcomp>)dropH   g?g      ? )Urg   r   r3   r   r   r   rC   r   r   r   r   r=   Z_define_bin_paramsrt   r   rj   r   r   r   r   r   rB   
_normalize_evalr   to_numpyro   r   r   maxr   
MultiIndexfrom_arraysIndexr   r   infr   r  minlocidxmaxrenamer   rp   	_get_axesrI   rK   barbarhsticky_edgesr-   r.   extendr   rL   fill_betweenplotfill_betweenxKeyErrorr   concatidxminr   autoscale_viewfiguredpiabs	transData	transformget_linewidthset_linewidthaxr'   rO   flat
capitalize_add_axis_labelsr   rN   patchesPatchlinesLine2Dra   )Or6   r   rX   rW   r   common_binsshrinkr)   kde_kwsrF   r!   line_kwsr   plot_kwsZauto_bins_with_weightsr   orientr   
histogramsr   all_weightsZmultiple_histogramsbin_kwsr   r    r   r   r   r   r   resr   r   r   r   Z	hist_normr   r*   r   r   Zsticky_statZbin_valsZsticky_datadefault_alpharY   Zhist_artistsbottomr)  	sub_colorrZ   	plot_funcartistsr  finalr-   r.   r   r   r  rV   r   Z	line_argsZsticky_xZsticky_ylineZhist_metadataZthin_bar_idxr   	left_edgedefault_linewidthZpts_xZpts_yZbinwidth_pointsZmax_linewidthr  Zmin_linewidth	default_x	default_yrU   r9   r9   r:   plot_univariate_histogram{  s   











	










 

z._DistributionPlotter.plot_univariate_histogramc           !   
   K   s  |
d u ri n|
  }
tf i |}t| jddh rb| j }|rf||d |d |dd  nd}g }| jddD ]2\}}||d |d |dd \}}|	| qvt| jddh  p|}|d ur|r| 
||}|dd |r|d ur| 
||}n|d	tttj|}nd }|d u r0d
}| jdddD ]*\}}|jrTq>||d |d |dd d\}\}}| drtd|}| drtd|}|jdkr|r|t|t| 9 }|  }d| jv r| |d }| |}||d< nB|dd }t|tr,t|dd}n|d u r@| |}||d< |sd|d urd| 
||}|d urv||d	< |s|r| 
||}|d urtj||}| |}tdd |j D }tdd |j  D }|j!|||j"fi |}|d ur"g |j#j$d d < g |j#j%d d < |r@|j&j'||	|fi |
 |rT|j(ddd |r>|j(ddd q>| j)d ur~| j)n| j*j+j,d }| -| d| jv r|ri }t.t/j0j1}| j)d ur| j)n| j*} | 2| |dddd|i  d S )Nr-   r.   r0   FTr   vminr   vmaxC0r/   r   r   r   cmapas_cmapc                 S   s   g | ]}|  qS r9   get_visibler   lr9   r9   r:   r   V  r   zA_DistributionPlotter.plot_bivariate_histogram.<locals>.<listcomp>c                 S   s   g | ]}|  qS r9   rM  rO  r9   r9   r:   r   W  r   r   r   r   )3rg   r	   r=   r3   r   r   define_bin_paramsr   r   rL   r|   rj   rB   r  r   ro   emptyr   r   r   r   rI   r   rM   strr   mamasked_less_equalr  anyxaxisget_gridlinesyaxis
pcolormeshTr  r-   r.   r"  colorbargridr)  r'   rO   r*  r,  r   rN   r-  r.  ra   )!r6   r1  r   threshpthreshpmaxrF   r!   r"   r#   r$   r   r5  r   r   Zfull_heightsr   r   Zsub_heightsZcommon_color_normrH  r   r   Zx_edgesZy_edgesrZ   rJ  r)  x_gridy_gridmeshrV   rU   r9   r9   r:   plot_bivariate_histogram  s    












 
z-_DistributionPlotter.plot_bivariate_histogramc	              
   K   s
  |d u r|dv }|rt jj}
nt jj}
t|	|
}	tdg d| tt| j	ddh }|rf|dv rfd}| 
| j}| | j|||||}| ||\}}|dkrdnd	tjf}|dkr|j |j f}ng }|r|d
krd}qd}nd}|	d|}| jdddD ]@\}}t| }z|| }W n tyB   Y qY n0 |j}|| }| |}d| j	v rx| |d }n|}| |	|d|||}d| j	v r|r|j|||fi |}
n|j||fi |\}
||
jjd d < ||
jjd d < nT|r|j |||fi |}
n|j||fi |\}
||
jjd d < ||
jjd d < q| j!d ur\| j!n| j"j#j$d	 }d }}| jdkrd}| jdkrd}| %||| d| j	v r|r|rt&t j'j(}
nt&t jjg g }
| j!d ur| j!n| j"}| )||
|d|||	i  d S )Nrd   r   )r   re   rW   r-   r.   TrW   r   r   r   r   r   r   rY   r/   r   Fr	  ZDensity)*rN   rh   ri   r/  r0  r   r   r<   r=   r3   r   rC   r   r   ro   r  r   r  r  rB   r   r   r   r  r  rI   rK   r  r  r  r-   r.   r  r)  r'   rO   r*  r,  r   r-  r.  ra   )r6   r   r   r   r   rW   rF   r!   r   r5  rV   subsetsr    r   r   Zsticky_densityZsticky_supportr;  rY   r   r   r   r   r   Z	fill_fromr)  r=  rZ   rD  rE  rU   r9   r9   r:   plot_univariate_density  s    



 z,_DistributionPlotter.plot_univariate_densityc           )   
      sr  |  }tf i |}tjddh s,d}j }i i  }}jdddD ]&\}}|ddg }| d	 }|d |d f}djv r|d }nd }t
|d}z|s||d|i\}}W n tjjy   d}Y n0 |r d	}|rNtj|td
d qN|\}}dr td|}dr8td|}||f}|rZ|t|t| 9 }t| }|||< |||< qN|d u rd}ttrt|dn$t	dk stdkrtd|rt|   fdd|D }nfdd| D }djv rPdD ]0}||v r| d}t|t || qnzt|ddh@ }|r~|s~ |} | |d< |s|s|g|d< |dd } t| t!rt"| dd} | d ur| |d< dD ]\}}!d|v r#|d }|r ||d< n
|g|d< $|}"|r.|"j%}#n|"j&}#t| }||vrNq|| }|| \}}|dd }$|#|||fd|| i|}%djvr|%j'd (|$ |r|
d u ri n|
}
|"j)j*|%|	|"fi |
 qԈj+d urj+nj,j-j.d }"/|" djv rn|rni }&|r.t0t1j2j3}'nt0t1j4j5g g }'j+d urPj+nj,}(6|(|'|ddd|&i  d S )Nr-   r.   Fr/   Tr   r   r0   zoKDE cannot be estimated (0 variance or perfect covariance). Pass `warn_singular=False` to disable this warning.r~   r   r   r   zlevels must be in [0, 1]c                    s   i | ]
}| qS r9   r9   )r   r   )common_levelsr9   r:   r   f  r   z?_DistributionPlotter.plot_bivariate_density.<locals>.<dictcomp>c                    s   i | ]\}}| | qS r9   )r|   )r   r   d)rJ   r6   r9   r:   r   h  s   )rJ  r   z* parameter ignored when using hue mapping.rJ  r   rK  labelrJ   r   )7rg   r
   r=   r3   r   r   r   r   r   r  r   r   ro   r   r   r   r   r   r   r   r   r   r   rM   r   r   r  
ValueErrorr|   listrx   rB   r   rS  r   rI   r  contourfcontourrh   	set_labelr"  r\  r)  r'   rO   r*  r,  r   rN   r-  r.  r/  r0  ra   ))r6   r   rW   rJ   r^  rF   r!   r"   r   r#   r$   r   Zcontour_kwsr   r   r   Zsupportsr   r   r   Zmin_variancer0   r   r   r   r   r   yyr   Zdraw_levelsparamZcoloring_givenrJ  r   r)  Zcontour_funcri  csetrZ   rV   rU   r9   )rg  rJ   r6   r:   plot_bivariate_density  s    















 
z+_DistributionPlotter.plot_bivariate_densityc              
   K   s  t f i |}tddd}|| j |d< | jddddD ]\}}|jrHq8|| j }|dd }	|||	d	\}
}| }d| jv r| |d |d
< | 	| jrt
d|}t
j |d< | jdkr||
f}d}n|
|f}d}|jdkrt|}nd}| |}|j|i |\}t|j|}d|f|d d < q8| jd ur>| jn| jjjd }|j }
d }}| jdkrn|
}| jdkr~|
}| ||| d| jv r|rttjjg g }|dd}| jd ur| jn| j}| ||ddd ||i  d S )Nr  r  r-   r.   r  r/   T)r   r   r0   r   rF   r   r   r-   r.   r   r   r	  rY   F)r   rQ   rC   r   rR  r   rg   r3   rI   r   ro   r   r  r   r   r  r  getattrr  r)  r'   rO   r*  r+  r,  r   rN   r/  r0  ra   )r6   r   r!   r5  r   Z
drawstylesr   r   r   r0   r   valsrZ   	plot_argsZstat_variabletop_edger)  rV   r  rD  rE  rY   rU   r9   r9   r:   plot_univariate_ecdf  sX    





 
z)_DistributionPlotter.plot_univariate_ecdfc                 K   s  | j ddD ]\}}| |}|dd |rv| \}}	d| jv rR|	|d 7 }	d| jv rh||d 7 }|j||	d d	| jv r|d
d  |dd  d| jv r| |d||| d| jv r| |d||| | | d	| jv r|rtt	j
jg g }
| ||
ddd di i  qd S )NTr   r  r   r-   r   r.   rs  r/   crF   F)r   r  rj   marginsr3   rB   _plot_single_rugr,  r   rN   r/  r0  ra   )r6   heightexpand_marginsr!   r_   r   r   r)  xmargymarglegend_artistr9   r9   r:   plot_rug  s.    






z_DistributionPlotter.plot_rugc                 C   s   || }t |}| |r&td|}d| jv r@| |d }nd}|dkr~t|j|j	}	t
t|dtd|g|g}
|dkrt|j	|j}	t
td|g|t|dg}
|
|ddg}|t|f|	|d| |j|dk|dkd	 dS )
z*Draw a rugplot along one axis of the plot.r   r/   Nr-   r   r   r.   )r&  r   )scalexscaley)r   r   ro   r   r3   rI   txblended_transform_factoryr%  	transAxescolumn_stackrepeattilereshapeadd_collectionr   r!  )r6   r   r   r|  r)  r_   vectorr   r   transZxy_pairsZ	line_segsr9   r9   r:   r{  -  s4    

z%_DistributionPlotter._plot_single_rug)T)__name__
__module____qualname__	semanticswide_structureflat_structurer5   propertyr?   rC   rD   ra   rK   r|   r   r   r   r   rF  rd  rf  rr  rx  r  r{  __classcell__r9   r9   r7   r:   r,   d   s@   



#

N 
N  o   ;E"r,   c                   @   s   e Zd Zejd ZdS )_DistributionFacetPlotter)r   r   N)r  r  r  r,   r  r9   r9   r9   r:   r  U  s   r  r   r   FTr   rb   ) r-   r.   r/   r0   r   r   r   binranger   r   r1  r   r   rX   rW   r2  r)   r3  r4  r^  r_  r`  r"   r#   r$   palette	hue_orderhue_normrF   r    r!   r)  c           %      K   s  t | t t d}"|"j|||d | d u r4t } |"j| |d |"jrv|rb|dkrZ| jn| j	}#n| j
}#t|#|||!}|"js| S |	d u r|" }	t|||||	|
d}$|"jr|"jf |||||||||||$|d|! n(|"jf |||||||||||$d|! | S )Nr1   r  ordernormr    rb   )r   r   r   r  r   r   )r   rX   rW   r2  r   r1  r)   r3  rF   r!   r   r4  )r1  r   r^  r_  r`  rF   r!   r"   r#   r$   r   )r,   get_semanticslocalsmap_huepltgca_attachr?   r  r  r  r   rD   r   rQ   rF  rd  )%r2   r-   r.   r/   r0   r   r   r   r  r   r   r1  r   r   rX   rW   r2  r)   r3  r4  r^  r_  r`  r"   r#   r$   r  r  r  rF   r    r!   r)  kwargspmethodr   r9   r9   r:   r   ^  st    
	r   aJ  Plot univariate or bivariate histograms to show distributions of datasets.

A histogram is a classic visualization tool that represents the distribution
of one or more variables by counting the number of observations that fall within
discrete bins.

This function can normalize the statistic computed within each bin to estimate
frequency, density or probability mass, and it can add a smooth curve obtained
using a kernel density estimate, similar to :func:`kdeplot`.

More information is provided in the :ref:`user guide <tutorial_hist>`.

Parameters
----------
{params.core.data}
{params.core.xy}
{params.core.hue}
weights : vector or key in ``data``
    If provided, weight the contribution of the corresponding data points
    towards the count in each bin by these factors.
{params.hist.stat}
{params.hist.bins}
{params.hist.binwidth}
{params.hist.binrange}
discrete : bool
    If True, default to ``binwidth=1`` and draw the bars so that they are
    centered on their corresponding data points. This avoids "gaps" that may
    otherwise appear when using discrete (integer) data.
cumulative : bool
    If True, plot the cumulative counts as bins increase.
common_bins : bool
    If True, use the same bins when semantic variables produce multiple
    plots. If using a reference rule to determine the bins, it will be computed
    with the full dataset.
common_norm : bool
    If True and using a normalized statistic, the normalization will apply over
    the full dataset. Otherwise, normalize each histogram independently.
multiple : {{"layer", "dodge", "stack", "fill"}}
    Approach to resolving multiple elements when semantic mapping creates subsets.
    Only relevant with univariate data.
element : {{"bars", "step", "poly"}}
    Visual representation of the histogram statistic.
    Only relevant with univariate data.
fill : bool
    If True, fill in the space under the histogram.
    Only relevant with univariate data.
shrink : number
    Scale the width of each bar relative to the binwidth by this factor.
    Only relevant with univariate data.
kde : bool
    If True, compute a kernel density estimate to smooth the distribution
    and show on the plot as (one or more) line(s).
    Only relevant with univariate data.
kde_kws : dict
    Parameters that control the KDE computation, as in :func:`kdeplot`.
line_kws : dict
    Parameters that control the KDE visualization, passed to
    :meth:`matplotlib.axes.Axes.plot`.
thresh : number or None
    Cells with a statistic less than or equal to this value will be transparent.
    Only relevant with bivariate data.
pthresh : number or None
    Like ``thresh``, but a value in [0, 1] such that cells with aggregate counts
    (or other statistics, when used) up to this proportion of the total will be
    transparent.
pmax : number or None
    A value in [0, 1] that sets that saturation point for the colormap at a value
    such that cells below constitute this proportion of the total count (or
    other statistic, when used).
{params.dist.cbar}
{params.dist.cbar_ax}
{params.dist.cbar_kws}
{params.core.palette}
{params.core.hue_order}
{params.core.hue_norm}
{params.core.color}
{params.dist.log_scale}
{params.dist.legend}
{params.core.ax}
kwargs
    Other keyword arguments are passed to one of the following matplotlib
    functions:

    - :meth:`matplotlib.axes.Axes.bar` (univariate, element="bars")
    - :meth:`matplotlib.axes.Axes.fill_between` (univariate, other element, fill=True)
    - :meth:`matplotlib.axes.Axes.plot` (univariate, other element, fill=False)
    - :meth:`matplotlib.axes.Axes.pcolormesh` (bivariate)

Returns
-------
{returns.ax}

See Also
--------
{seealso.displot}
{seealso.kdeplot}
{seealso.rugplot}
{seealso.ecdfplot}
{seealso.jointplot}

Notes
-----

The choice of bins for computing and plotting a histogram can exert
substantial influence on the insights that one is able to draw from the
visualization. If the bins are too large, they may erase important features.
On the other hand, bins that are too small may be dominated by random
variability, obscuring the shape of the true underlying distribution. The
default bin size is determined using a reference rule that depends on the
sample size and variance. This works well in many cases, (i.e., with
"well-behaved" data) but it fails in others. It is always a good to try
different bin sizes to be sure that you are not missing something important.
This function allows you to specify bins in several different ways, such as
by setting the total number of bins to use, the width of each bin, or the
specific locations where the bins should break.

Examples
--------

.. include:: ../docstrings/histplot.rst

returnsseealso)r%   r  r  scottr   g?   r~   )r-   r.   r/   r0   r  r  r  rF   rW   r   r   r   r   	bw_method	bw_adjustr   r    rJ   r^  gridsizer   rm   r!   r"   r#   r$   r)  c          '      K   sL  d|v rd}t | |dd }|d urv|rPd}|d u rD||  } }qT|| }}nd}td| d}tj|tdd	 |d
d } | d urtd|  d}tj|tdd	 | }|dd d urtd}tj|tdd	 |dd }!|!d ur|!rd}td| d}tj|tdd	 |dd }"|"d urV|"}	td|" d}tj|tdd	 |d|}t| t	t
 d}#|#j|||d |d u rt }|#j|ddg|d |	r|jn|j}$t|$|||}|#js|S t||||||d}%|#jr | }&|#jf |
|||	||||%d|& n(|#jf ||	|||||||||%d| |S )Ndata2zD`data2` has been removed (replaced by `y`); please update your code.verticalassigning data to `y`.assigning data to `x`.2

        The `vertical` parameter is deprecated; X
        This will become an error in seaborn v0.13.0; please update your code.
        r   r   bwzo

        The `bw` parameter is deprecated in favor of `bw_method` and `bw_adjust`.
        Setting `bw_method=z`, but please see the docs for the new parameters
        and update your code. This will become an error in seaborn v0.13.0.
        kernelz

        Support for alternate kernels has been removed; using Gaussian kernel.
        This will become an error in seaborn v0.13.0; please update your code.
        shade_lowestr   zH

        `shade_lowest` has been replaced by `thresh`; setting `thresh=zY.
        This will become an error in seaborn v0.13.0; please update your code.
        shadezF

        `shade` is now deprecated in favor of `fill`; setting `fill=zZ`.
        This will become an error in seaborn v0.14.0; please update your code.
        n_levelsr1   r  numericdatetimeallowed_typesr    )r  r  r  r   rm   r   )r   r   r   rW   rF   r!   r   r   )r   rW   rJ   r^  r!   rF   r   r"   r#   r$   r   )	TypeErrorrB   textwrapdedentr   r   r   FutureWarningr,   r  r  r  r  r  r  r  r  r   rD   rQ   r?   rg   rf  rr  )'r2   r-   r.   r/   r0   r  r  r  rF   rW   r   r   r   r   r  r  r   r    rJ   r^  r  r   rm   r!   r"   r#   r$   r)  r  r   r  action_takenr  r  r  r  r  r   r5  r9   r9   r:   r   =  s    









		r   a  Plot univariate or bivariate distributions using kernel density estimation.

A kernel density estimate (KDE) plot is a method for visualizing the
distribution of observations in a dataset, analogous to a histogram. KDE
represents the data using a continuous probability density curve in one or
more dimensions.

The approach is explained further in the :ref:`user guide <tutorial_kde>`.

Relative to a histogram, KDE can produce a plot that is less cluttered and
more interpretable, especially when drawing multiple distributions. But it
has the potential to introduce distortions if the underlying distribution is
bounded or not smooth. Like a histogram, the quality of the representation
also depends on the selection of good smoothing parameters.

Parameters
----------
{params.core.data}
{params.core.xy}
{params.core.hue}
weights : vector or key in ``data``
    If provided, weight the kernel density estimation using these values.
{params.core.palette}
{params.core.hue_order}
{params.core.hue_norm}
{params.core.color}
fill : bool or None
    If True, fill in the area under univariate density curves or between
    bivariate contours. If None, the default depends on ``multiple``.
{params.dist.multiple}
common_norm : bool
    If True, scale each conditional density by the number of observations
    such that the total area under all densities sums to 1. Otherwise,
    normalize each density independently.
common_grid : bool
    If True, use the same evaluation grid for each kernel density estimate.
    Only relevant with univariate data.
{params.kde.cumulative}
{params.kde.bw_method}
{params.kde.bw_adjust}
warn_singular : bool
    If True, issue a warning when trying to estimate the density of data
    with zero variance.
{params.dist.log_scale}
levels : int or vector
    Number of contour levels or values to draw contours at. A vector argument
    must have increasing values in [0, 1]. Levels correspond to iso-proportions
    of the density: e.g., 20% of the probability mass will lie below the
    contour drawn for 0.2. Only relevant with bivariate data.
thresh : number in [0, 1]
    Lowest iso-proportion level at which to draw a contour line. Ignored when
    ``levels`` is a vector. Only relevant with bivariate data.
gridsize : int
    Number of points on each dimension of the evaluation grid.
{params.kde.cut}
{params.kde.clip}
{params.dist.legend}
{params.dist.cbar}
{params.dist.cbar_ax}
{params.dist.cbar_kws}
{params.core.ax}
kwargs
    Other keyword arguments are passed to one of the following matplotlib
    functions:

    - :meth:`matplotlib.axes.Axes.plot` (univariate, ``fill=False``),
    - :meth:`matplotlib.axes.Axes.fill_between` (univariate, ``fill=True``),
    - :meth:`matplotlib.axes.Axes.contour` (bivariate, ``fill=False``),
    - :meth:`matplotlib.axes.contourf` (bivariate, ``fill=True``).

Returns
-------
{returns.ax}

See Also
--------
{seealso.displot}
{seealso.histplot}
{seealso.ecdfplot}
{seealso.jointplot}
{seealso.violinplot}

Notes
-----

The *bandwidth*, or standard deviation of the smoothing kernel, is an
important parameter. Misspecification of the bandwidth can produce a
distorted representation of the data. Much like the choice of bin width in a
histogram, an over-smoothed curve can erase true features of a
distribution, while an under-smoothed curve can create false features out of
random variability. The rule-of-thumb that sets the default bandwidth works
best when the true distribution is smooth, unimodal, and roughly bell-shaped.
It is always a good idea to check the default behavior by using ``bw_adjust``
to increase or decrease the amount of smoothing.

Because the smoothing algorithm uses a Gaussian kernel, the estimated density
curve can extend to values that do not make sense for a particular dataset.
For example, the curve may be drawn over negative values when smoothing data
that are naturally positive. The ``cut`` and ``clip`` parameters can be used
to control the extent of the curve, but datasets that have many observations
close to a natural boundary may be better served by a different visualization
method.

Similar considerations apply when a dataset is naturally discrete or "spiky"
(containing many repeated observations of the same value). Kernel density
estimation will always produce a smooth curve, which would be misleading
in these situations.

The units on the density axis are a common source of confusion. While kernel
density estimation produces a probability distribution, the height of the curve
at each point gives a density, not a probability. A probability can be obtained
only by integrating the density across a range. The curve is normalized so
that the integral over all possible values is 1, meaning that the scale of
the density axis depends on the data values.

Examples
--------

.. include:: ../docstrings/kdeplot.rst


proportion)r-   r.   r/   r0   r   complementaryr  r  r  r    r!   r)  c                K   s   t | t t d}|j|||	d |d u r4t }|j||
d |d|dd }t|j	||||d< |j
st|S |jstdt||d}|jf ||d| |S )	Nr1   r  r  rF   ry  (Bivariate ECDF plots are not implemented)r   r  )r   r!   )r,   r  r  r  r  r  r  rB   r   r  rD   r?   NotImplementedErrorrQ   rx  )r2   r-   r.   r/   r0   r   r  r  r  r  r    r!   r)  r  r  rF   r   r9   r9   r:   r   U  s2    
r   ar  Plot empirical cumulative distribution functions.

An ECDF represents the proportion or count of observations falling below each
unique value in a dataset. Compared to a histogram or density plot, it has the
advantage that each observation is visualized directly, meaning that there are
no binning or smoothing parameters that need to be adjusted. It also aids direct
comparisons between multiple distributions. A downside is that the relationship
between the appearance of the plot and the basic properties of the distribution
(such as its central tendency, variance, and the presence of any bimodality)
may not be as intuitive.

More information is provided in the :ref:`user guide <tutorial_ecdf>`.

Parameters
----------
{params.core.data}
{params.core.xy}
{params.core.hue}
weights : vector or key in ``data``
    If provided, weight the contribution of the corresponding data points
    towards the cumulative distribution using these values.
{params.ecdf.stat}
{params.ecdf.complementary}
{params.core.palette}
{params.core.hue_order}
{params.core.hue_norm}
{params.dist.log_scale}
{params.dist.legend}
{params.core.ax}
kwargs
    Other keyword arguments are passed to :meth:`matplotlib.axes.Axes.plot`.

Returns
-------
{returns.ax}

See Also
--------
{seealso.displot}
{seealso.histplot}
{seealso.kdeplot}
{seealso.rugplot}

Examples
--------

.. include:: ../docstrings/ecdfplot.rst

g?)
r-   r.   r/   r|  r}  r  r  r  r!   r)  c       
         K   sv  | dd }| dd }|d ur>|} td}tj|tdd |d ur|dkrT| }n|dkr`| }td| d	}tj|tdd | d
d }|d ur|rd}|d u r||  } }q|| }}nd}td| d}tj|tdd d }t| tt d}|j	|||d |
d u rt
 }
||
 | d| dd }t|
j||||d< |js\|
S |j|||	fi | |
S )Nar   z

        The `a` parameter has been replaced; use `x`, `y`, and/or `data` instead.
        Please update your code; This will become an error in seaborn v0.13.0.
        r   r   r-   r.   z=

        The `axis` parameter has been deprecated; use the `zl` parameter instead.
        Please update your code; this will become an error in seaborn v0.13.0.
        r  r  r  r  r  r1   r  rF   ry  )rB   r  r  r   r   r   r,   r  r  r  r  r  r  r   r  rD   r  )r2   r-   r.   r/   r|  r}  r  r  r  r!   r)  r  r  r   r   r  r  r0   r  rF   r9   r9   r:   r     sT    





r   aG  Plot marginal distributions by drawing ticks along the x and y axes.

This function is intended to complement other plots by showing the location
of individual observations in an unobtrusive way.

Parameters
----------
{params.core.data}
{params.core.xy}
{params.core.hue}
height : float
    Proportion of axes extent covered by each rug element. Can be negative.
expand_margins : bool
    If True, increase the axes margins by the height of the rug to avoid
    overlap with other elements.
{params.core.palette}
{params.core.hue_order}
{params.core.hue_norm}
legend : bool
    If False, do not add a legend for semantic variables.
{params.core.ax}
kwargs
    Other keyword arguments are passed to
    :meth:`matplotlib.collections.LineCollection`

Returns
-------
{returns.ax}

Examples
--------

.. include:: ../docstrings/rugplot.rst

r*      )r-   r.   r/   r   r   r0   kindrugrug_kwsr    r!   r  r  r  rF   col_wrap	row_order	col_orderr|  aspect	facet_kwsc          '      K   sb  t | t t d}|j|||d tdg d| d|v r\d|}t|t |	d dD ].}||j
v r`|j
| d u r`d| d|j
|< q`|jj|j
d	}|jd d |j  f }|j
d
}|j
d}|d u ri }tf ||||||||d|}|dkrddg}nd }|j|||
d |js2|S |d u rJ|d u rJd}||d< |dkr| }i } t| tjt i }!|  D ]\}"}#|	|"|#|!|"< q|!d d u r| |!d< |!|d< |d| |jrt||jt |jf i | nt||jt |jf i | n0|dkr| }$i } t| tjt  i }!|  D ]\}"}#|$	|"|#|!|"< qF|!|$d< ||$d< |jrt|$|j!t  |j!f i |$ nt|$|j"t  |j"f i |$ n|dkrF| }%i }!i } t| t#jt$ |  D ]\}"}#|%	|"|#|!|"< q|!|%d< ||%d< |jr>t|%|j%t$ |j%f i |% nt&d|r|	d u rZi }	t|	|j't( d|	d< |d ur||	d< |j'f i |	 |j)|j
d|j*j+d , |j
d|j*j+d - d |.  |/  | d ur:|d us|d ur:t0| t1j2st12| } t1j3| |j4|j4j5| j ddd|_4n$d d! |j
 D }&|jj|&d	|_4|S )"Nr1   r  r  )r*   r)   r+   r)  zg`displot` is a figure-level function and does not accept the ax= parameter. You may wish to try {}plot.)r   r   r   )r   r   r   )r2   r   r   r  r  r  r|  r  r)   r  r  r  rI  r!   r*   r   r   rF   r+   r  Fr-   r   r.   )x_vary_varT)
left_indexright_indexc                 S   s*   i | ]"\}}||d u r"d| dn|qS )Nr   r9   r   r9   r9   r:   r     s   zdisplot.<locals>.<dictcomp>)6r  r  r  r  r   formatr   r   r   rB   r3   r   r  r  r   
duplicatedr   r   r  rD   rg   r   r	   r5   r   r   r   rj   r?   rF  rd  r
   r   rf  rr  r   r   rx  r  r  r   set_axis_labelsrO   r*  
get_xlabel
get_ylabel
set_titlestight_layoutrM   r   r   merger2   
difference)'r2   r-   r.   r/   r   r   r0   r  r  r  r    r!   r  r  r  rF   r  r  r  r|  r  r  r  r  r   r   	grid_datacol_namerow_namer   r  hist_kwsZestimate_defaultsr   r   default_valr3  Zecdf_kwsZ	wide_colsr9   r9   r:   r   ?  s    

	








r   a/	  Figure-level interface for drawing distribution plots onto a FacetGrid.

This function provides access to several approaches for visualizing the
univariate or bivariate distribution of data, including subsets of data
defined by semantic mapping and faceting across multiple subplots. The
``kind`` parameter selects the approach to use:

- :func:`histplot` (with ``kind="hist"``; the default)
- :func:`kdeplot` (with ``kind="kde"``)
- :func:`ecdfplot` (with ``kind="ecdf"``; univariate-only)

Additionally, a :func:`rugplot` can be added to any kind of plot to show
individual observations.

Extra keyword arguments are passed to the underlying function, so you should
refer to the documentation for each to understand the complete set of options
for making plots with this interface.

See the :doc:`distribution plots tutorial <../tutorial/distributions>` for a more
in-depth discussion of the relative strengths and weaknesses of each approach.
The distinction between figure-level and axes-level functions is explained
further in the :doc:`user guide <../tutorial/function_overview>`.

Parameters
----------
{params.core.data}
{params.core.xy}
{params.core.hue}
{params.facets.rowcol}
kind : {{"hist", "kde", "ecdf"}}
    Approach for visualizing the data. Selects the underlying plotting function
    and determines the additional set of valid parameters.
rug : bool
    If True, show each observation with marginal ticks (as in :func:`rugplot`).
rug_kws : dict
    Parameters to control the appearance of the rug plot.
{params.dist.log_scale}
{params.dist.legend}
{params.core.palette}
{params.core.hue_order}
{params.core.hue_norm}
{params.core.color}
{params.facets.col_wrap}
{params.facets.rowcol_order}
{params.facets.height}
{params.facets.aspect}
{params.facets.facet_kws}
kwargs
    Other keyword arguments are documented with the relevant axes-level function:

    - :func:`histplot` (with ``kind="hist"``)
    - :func:`kdeplot` (with ``kind="kde"``)
    - :func:`ecdfplot` (with ``kind="ecdf"``)

Returns
-------
{returns.facetgrid}

See Also
--------
{seealso.histplot}
{seealso.kdeplot}
{seealso.rugplot}
{seealso.ecdfplot}
{seealso.jointplot}

Examples
--------

See the API documentation for the axes-level functions for more details
about the breadth of options available for each plot kind.

.. include:: ../docstrings/displot.rst

c                 C   s   t | } t| dk rdS t jt | ddg}d| t| d  }|dkr^tt | jS tt 	| 
 |   | S dS )z;Calculate number of hist bins using Freedman-Diaconis rule.r   r   K      gUUUUUU?r   N)ro   rp   r   subtractreducenanpercentiler   sqrtsizeceilr  r  )r  iqrr   r9   r9   r:   _freedman_diaconis_binsV	  s    
r  c           !         s  |r|sd}nd}t d| d}tj|tdd |du rDt }t|}|du rpt| drp| j	}|durpd	}|dur||} t
| t} | jd
kr|  } t| } |p|p du}|du ri n| }|du ri n| }|du ri n| }|	du ri n|	 }	|
du rH|r&|d|  \}n||  d\}| }
|  |dur|rb||d< n.|rr||d< n|r||d< n r||	d< |r|du rtt| d}|dd |d| |rdnd}|d|
}|j| |f||d| ||
kr||d< |rdnd}|r^|d|
}tf i || i||d| ||
kr^||d< |r|d|
}tf i || i||d| ||
kr||d<  durh fdd}|	dd}|	dd}|	dd}|	dt
j t
jf}t|  | jd
d  }t | ||||} !| ||} |r>| | }} |j|| fd|i|	 |dkrh||	d< |r|r|"| n
|#| |S )!ad  
    DEPRECATED

    This function has been deprecated and will be removed in seaborn v0.14.0.
    It has been replaced by :func:`histplot` and :func:`displot`, two functions
    with a modern API and many more capabilities.

    For a guide to updating, please see this notebook:

    https://gist.github.com/mwaskom/de44147ed2974457ad6372750bbe5751

    z;`kdeplot` (an axes-level function for kernel density plots)z2`histplot` (an axes-level function for histograms)z

    `distplot` is a deprecated function and will be removed in seaborn v0.14.0.

    Please adapt your code to use either `displot` (a figure-level function with
    similar flexibility) or z.

    For a guide to updating your code to use the new functions, please see
    https://gist.github.com/mwaskom/de44147ed2974457ad6372750bbe5751
    r   r   Nr   Tr   r   ri  2   rY   g?r   
horizontalr  rF   )orientationrF   r.   r-   )r)  rF   c                    s    j | gR  S )N)pdf)r-   fitr%   r9   r:   r  	  s    zdistplot.<locals>.pdfz#282828r  r  r   r~   rm   )ddof)$r  r  r   r   r   r  r  r<   hasattrr   ro   rp   floatndimsqueezer   rg   r  mean	get_colorremover  r  rj   rB   r*   r   r   r  r   scotts_factorstdr   r  
set_ylabel
set_xlabel)!r  r   r*   r)   r  r  r  r3  r  fit_kwsrF   r  Z	norm_histaxlabelri  r)  r-   Zaxes_level_suggestionr   Zlabel_axrA  r  Z
hist_colorr   Z	kde_colorZ	rug_colorr  Z	fit_colorr  r   rm   r  r.   r9   r  r:   r   e	  s    









 
 





r   )N)N)N)N)N)NNTTFNNNNNNFFNNNN)D__doc__numbersr   	functoolsr   r   r  r   numpyro   pandasr   
matplotlibrN   matplotlib.pyplotpyplotr  matplotlib.transforms
transformsr  matplotlib.colorsr   matplotlib.collectionsr   _oldcorer   _statisticsr   r	   r
   Z_stats.countingr   axisgridr   r   utilsr   r   r   r   r   r   palettesr   externalr   Zexternal.kder   _docstringsr   r   __all__rQ   Z_dist_paramsfrom_nested_componentsfrom_function_paramsr5   _param_docsr,   r  r   r  r   r   r   r   r  r   r9   r9   r9   r:   <module>   s    !


         z
 ^{  


 z  829 

P$+ 
 ALW    