3
hZj             $   @   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jZddlj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 m!Z! ddl"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l.m/Z/m0Z0 ddddddgZ1e2dddddddZ3e/j4e0d e/e!e/e3e/j5ej6e/j5ej6e/j5ej6dZ7G d d! d!eZ8G d"d# d#e8Z9dHd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;e7e0d- e0d. d/e:_ e-dIddd&ddd0d1dd'd&dd&ddddddddd(d'd&d2d3d4ddddddd'd5!d6dZ<d7j;e7e0d- e0d. d/e<_ dJddddd8d&ddddd'dd9d:dZ=d;j;e7e0d- e0d. d/e=_ e-dKd<ddddddddd'd'dd=d>dZ>d?j;e7e0d- e0d. d/e>_ dLddddddd@d&ddd'ddddddddAdddBdCdZ?dDj;e7e0d- e0d. d/e?_ dEdF Z@dMdGdZAdS )Nz1Plotting functions for visualizing distributions.    )Number)partialN)to_rgba)LineCollection)stats   )VectorPlotter)KDE	HistogramECDF)	FacetGrid_facet_docs)	remove_na_kde_support_normalize_kwargs_check_argument_assign_default_kwargs)color_palette)husl)_deprecate_positional_args)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 )0_DistributionPlotterxyhueweightsz@valuesz@columns)r,   r.   Nc                s   t  j||d d S )N)data	variables)super__init__)selfr0   r1   )	__class__ 8/tmp/pip-build-riy7u7_k/seaborn/seaborn/distributions.pyr3   i   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setr1   )r4   r6   r6   r7   
univariateq   s    z_DistributionPlotter.univariatec             C   s"   | j stdddhj| jj S )z3Return the variable with data for univariate plots.zThis is not a univariate plotr,   r-   )r:   AttributeErrorintersectionr1   pop)r4   r6   r6   r7   data_variablez   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-   )r8   r9   r1   )r4   r6   r6   r7   has_xy_data   s    z _DistributionPlotter.has_xy_datac	             C   s   g }	g }
xD| j jD ]8}| j |}|	j|f | j|||||| |
j| qW 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.titler.   )r@   Zlabel_orderN)_hue_maplevelsappend_artist_kws
isinstancemplaxesZAxesr    r1   dictzipZ
add_legend
var_levels)r4   ax_objartistfillelementr   alpha
artist_kwsZ
legend_kwsZhandleslabelslevelcolorZlegend_datar6   r6   r7   _add_legend   s     
 z _DistributionPlotter._add_legendc             C   s   |j  }|rV|jdt|| |d
ks.|dkrB|jdtjd  q|jdt|d n.|dkrvd|d< t|||d< nt|||d	< |S )z<Handle differences between artists in filled/unfilled plots.	facecolorstackrM   barsZ	edgecolorzpatch.edgecolorr   nonerS   )rV   rM   )copy
setdefaultr   rF   ZrcParams)r4   kwsrM   rN   r   rS   rO   r6   r6   r7   rD      s    z _DistributionPlotter._artist_kwsc       	      C   s^   t j|}t j|}t j|ddd }t j||j  }t j|d| }t j||dd}|S )z:Return data levels corresponding to quantile cuts of mass.Nr   clip)mode)npasarrayZravelsortcumsumsumZsearchsortedZtake)	r4   r0   ZquantileZisopropvaluesZsorted_valuesZnormalized_valuesidxrB   r6   r6   r7   _quantile_to_level   s    

z'_DistributionPlotter._quantile_to_levelc             C   s   t |\}}}}tj|||\}}}tjddtddd }tjd}	||	dddf< |tj| |	dddf< tjddd|	ddd	f< tjd
d |	D dd}
t	j
j|
ddd S )z0Return a sequential colormap given a color seed.r   gffffff?   N   r   #   P      c             S   s   g | ]}t j| qS r6   )r   Zhusl_to_rgb).0Zhslr6   r6   r7   
<listcomp>   s    z9_DistributionPlotter._cmap_from_color.<locals>.<listcomp>r^   gffffffr@)rg   rh   r^   )r   r   Zrgb_to_huslr_   linspaceintzeroscosr\   rF   colorsZListedColormap)r4   rS   rgb_hsxxZramprr   r6   r6   r7   _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.Zcategoricalr,   r-   )r:   	var_typesr>   )r4   discreteZ
discrete_xZ
discrete_yr6   r6   r7   _default_discrete   s    z&_DistributionPlotter._default_discretec             C   s  dd |j  D }d| jkr$||fS |dkrdtj|jdddddf }i }xRttt|jj	 D ]:\}}|j
dd|j
d	df}|j|g  || j| qfW |j }x|j D ]}|jdd|f jd
d}	|jdd|f jd
d|jdd|f< |dkr0|jdd|f j|	dd|jdd|f< |jdd|f jdddjd|jdd|f< qW |dkr| jd }
t|
}xn|D ]f}t|d }|| jdd}|d  |  < |d  |
j||d  7  < |jddgd ||< qW ||fS )z?Modify the density data structure to handle multiple densities.c             S   s   i | ]\}}t j||qS r6   )r_   Z
zeros_like)rl   kvr6   r6   r7   
<dictcomp>   s    z:_DistributionPlotter._resolve_multiple.<locals>.<dictcomp>r.   rV   rM   Nr   colrowcolumns)axisindexr   dodgeheights)namewidthsedges)rV   rM   r^   )itemsr1   pd	DataFrameiloc	enumeratemaprH   r   tolistgetrZ   rC   rY   rd   rc   rb   divshiftZfillnarJ   lenreset_indexr   Z	set_index)r4   Zcurvesr   	baselinesZcolumn_groupsiZkeydZ	facet_keycolsZnorm_constantZ
hue_levelsnkeyrR   r)   r6   r6   r7   _resolve_multiple   s@    

(






z&_DistributionPlotter._resolve_multipleTc             C   s  t f |}| jj }t| jddh rD|rH| jj }	|j|	|  nd}i }
x| jdddD ]\}}|j }|| }|j }t	j
|dstj|rd}|r\tj|t q\d	| jkr|d	 }nd }|||d
\}}|rtjd|}|r|t|t| 9 }t|j }tj||d|
|< q\W |
S )Nr,   r-   Fr.   T)from_comp_datar   zfDataset has 0 variance; skipping density estimate. Pass `warn_singular=False` to disable this warning.r/   )r/   
   )r   )r	   	plot_datadropnar9   r1   	comp_dataZdefine_support	iter_datavarmathiscloser_   isnanwarningswarnUserWarningpowerr   tupler   r   Series)r4   r>   common_normcommon_gridestimate_kwsr   warn_singular	estimatorall_dataall_observations	densitiessub_varssub_dataobservationsZobservation_variancemsgr/   densitysupportr   r6   r6   r7   _compute_univariate_density  s8    




z0_DistributionPlotter._compute_univariate_densityc       M      K   s 
  |d kri n|j  }|d kr i n|j  }|d kr4i n|j  }tdddddg| tdddd	g| |d
 rz|dkrztdd| jko|d dko|d d ko|d
  }|rd}tj|t d|d< |d dkrd}tf |}i }t| jddh r&| j	j
 }|r*|| j }|j||jdd d nd}|rl|jdd |d |d< | j| j}| j| j||||dd}xP| jdddD ]<\}}t|j }|j
 }|| j }d| jkr|d }nd }|||d\}}|r||kr|| }|jr|j }n|tj| j }||  |9  < | j| jr6tjd|}tj|}|| } |d d= d| d  |  }tjjtj|d!d"tj| d#d"g}!tj||!d$d%}"|r|"t|t| 9 }"|"||< q~W | j ||\}}#|r| j ||dkrd n|\}}$|dkrd>ndtj!f}%|dkrP|j"j# }&|&d! }|&d# } |j$ |j | j%|j&   f}'ng }'d| jkr>| j'd kr|	d krzd&n|	}(n|r| j(| j d'krd })|j)d(|	}(|(d krd&}(n<t*j+j,}*t-||*}| j'j.g g fd)|	i|})t|)j/ j0 }(n6t*j1j2}*t-||*}| j'j3g g fd)|	i|\})|)j4 }(|)d k	r>|)j5  |rd| jkrn|dkrn|dkrhd*nd+}+n|rzd*}+nd,}+nd}+|j)d-|+},g }-xx| jddd.D ]d\}}$t|j }|| j6d$j7 }"tj8|#| }.| j9|}/d| jkr| j:|d }	n|(}	| j;|||||	|,}0|dkr| jdkr6|/j<n|/j=}1|1|"d! |"d$ |. |"d# |.fd/d0i|0}2x\|2D ]T}3| jdkr|'|3j>j?d d < |%|3j>j@d d < n |%|3j>j?d d < |'|3j>j@d d < qlW |-jA|2 nv|dkrF|"jBd? }4tjC|"d! |4d! |4d#  }5tjC|"d$ |4d$ }6tjC|.|.d@ }7| jdkr<d1}8d2}9nd1}8d3}9n2|d	krx|"d! |"d# d   }5|"d$ }6|.}7d }8d }9| jdkr|r|/j.|5|7|6fd|8i|0}*n|/j3|5|6fd4|9i|0\}*|'|*j>j?d d < |%|*j>j@d d < n\|r|/jD|5|7|6fd|8i|0}*n|/j3|6|5fd4|9i|0\}*|%|*j>j?d d < |'|*j>j@d d < |-jC|* |ry|| }W n tEk
rt   wY nX |j"}:d| jkr|:|f};d dtj!f }<}=n||:f};dtj!fd  }<}=tF|	d|d)< |/j3|;|\}>|<d k	r|<|>j>j?d d < |=d k	r|=|>j>j@d d < qW |dk	rJd5|k	rJtjGd6d7 |j D j7dd8}?|?d# jH }@|?j%|@d#f }A|?j%|@d!f }BtIj!}Cx| j D ]|\}}$| j9|}/|/jJ  d9|/jKjL tM|/jNjO|B|A gd  |/jNjO|Bgd    \}D}E| jdkr|D}Fn|E}Ft$d:|F |C}Cq|W xL|-D ]D}3|3jP }G|	s|Gd;9 }Gt$|C|G}H|	s:d*}It|H|I}H|3jQ|H 	qW | j'd k		r\| j'n| jRjSjTd }/d< }J}K| jdk	r|jUjV }K| jdk	r|jUjV }J| jW|/|J|K d| jk
r|

r|	s|dk	rtXt*j+jY}*ntXt*j1j2g g }*| j'd k		r| j'n| jR}L| jZ|L|*||||,|i  d S )ANr   layerrV   rM   r   rN   rW   steppolyr|   z0`element` must be 'bars' when `discrete` is Truer/   binsautobinwidthzb`bins` cannot be 'auto' when using weights. Setting `bins=10`, but you will likely want to adjust.r   statcountFr,   r-   )r/   cutr   
cumulative)r   r.   T)r   r   rk   r   )r   r   r   )r   r   C0datetimerU   rS   g      ?g      ?g      ?rO   )reverseZalignZedgepostz
steps-postz	steps-pre	drawstyle	linewidthc             S   s   g | ]\}}|j j qS r6   )r   to_frame)rl   rv   rw   r6   r6   r7   rm     s    zB_DistributionPlotter.plot_univariate_histogram.<locals>.<listcomp>)ZdropH   g?g      ? r^   )r   r   r^   r^   )[rY   r   
ValueErrorr1   r   r   r   r
   r9   r   r   r>   define_bin_paramsr   rZ   _log_scaledr   r   r   r   r   maxr_   Zdiffrc   r   r   Z
MultiIndexZfrom_arraysIndexr   r   r   infr   r   minlocZidxmaxaxr{   r=   rF   patchesZ	Rectangler   fill_betweenget_facecolorsqueezelinesLine2Dplot	get_colorremoverenamer   r`   	_get_axesrA   rD   barZbarhsticky_edgesr,   r-   extendr   rC   fill_betweenxKeyErrorr   concatZidxminr   autoscale_viewfigureZdpiabs	transData	transformZget_linewidthZset_linewidthr&   rG   flatr   
capitalize_add_axis_labelsr   PatchrT   )Mr4   r   rN   rM   r   common_binsshrinkr(   kde_kwsrS   r    line_kwsr   plot_kwsZauto_bins_with_weightsr   r   Z
histogramsr   r   r   r   r   r   r   r   r/   r   r   r   Z	hist_normZorig_widthsr   r   r)   r   rv   Zsticky_statZbin_valsZsticky_datadefault_colorscoutrL   default_alpharO   Zhist_artistsZbottomr   rP   Z	plot_funcZartistsr   finalr,   r-   ru   r   r   r   Z	line_argsZsticky_xZsticky_ylineZhist_metadataZthin_bar_idxr   Z	left_edgeZdefault_linewidthZpts_xZpts_yZbinwidth_pointsZmax_linewidthr   Zmin_linewidth	default_x	default_yrK   r6   r6   r7   plot_univariate_histogramY  s   










	



















 

z._DistributionPlotter.plot_univariate_histogramc       !   	   K   s  |
d kri n|
j  }
tf |}t| jddh r^| jj }|rb|j|d |d |jdd  nd}g }xJ| jddD ]:\}}|j }||d |d |jdd \}}|j	| qtW t| jddh  p|}|d k	r|r| j
||}|jdd |r&|d k	r| j
||}n|jd	tttj|}nd }|d kr8d
}xB| jdddD ].\}}|j }|jrhqJ||d |d |jdd d\}\}}| jdrtjd|}| jdrtjd|}|jdkr|r|t|t| 9 }|j  }d| jkr| j|d }| j|}||d< nB|jdd }t|tr@t|dd}n|d krT| j|}||d< | rz|d k	rz| j
||}|d k	r||d	< | r|r| j
||}|d k	rtjj||}| j|}tdd |jj D }tdd |j j D }|j!|||j"f|}|d k	r6g |j#j$d d < g |j#j%d d < |rP|j&j'||	|f|
 |rd|j(ddd |rJ|j(ddd qJW | j)d k	r| j)n| j*j+j,d }| j-| d| jkr|ri }t.t/j0j1}| j)d k	r| j)n| j*} | j2| |dddd|i  d S )Nr,   r-   r/   FT)r   Zvminr   vmaxr   r.   )r/   r   r   cmap)as_cmapc             S   s   g | ]}|j  qS r6   )get_visible)rl   lr6   r6   r7   rm   N  s    zA_DistributionPlotter.plot_bivariate_histogram.<locals>.<listcomp>c             S   s   g | ]}|j  qS r6   )r  )rl   r  r6   r6   r7   rm   O  s    )r   r   r   )3rY   r
   r9   r1   r   r   r   r   r   rC   rf   rZ   r=   r   r   r_   emptyr   r   r   r   rA   rz   rE   strr   maZmasked_less_equalr   anyZxaxisZget_gridlinesZyaxisZ
pcolormeshTr   r,   r-   r   colorbarZgridr   r&   rG   r   r   r   rF   r   r   rT   )!r4   r   r   threshpthreshpmaxrS   r    r!   r"   r#   r   r   r   r   Zfull_heightsrv   r   Zsub_heightsZcommon_color_normr   r   r   Zx_edgesZy_edgesrP   r   r   Zx_gridZy_gridZmeshrL   rK   r6   r6   r7   plot_bivariate_histogram  s    











 
z-_DistributionPlotter.plot_bivariate_histogramc              K   s  |d kr|dk}|rt jj}	nt jj}	t||	}tddddg| tt| j	ddh }
|
rh|dkrhd}| j
| j}| j| j|||||}| j||\}}|dkrdndtjf}|dkr|jj |jj f}ng }d
| j	kr| jd kr
|jdd }|d krdn|}n|rz| j| j dkrJd }|jd|jdd }|d krld}n"| jjg g f|}t|j j }|jdd  n| jjg g f|\}|j }|d k	r|j  |jdd  |r|dkrd}nd}nd	}|jd|}xD| jd
ddD ]0\}}t|j }y|| }W n tk
r.   wY nX |j}|| }| j |}d
| j	krd| j!|d
 }n|}| j"||d|||}d| j	kr|r|j|||f|}	n|j||f|\}	||	j#j$d d < ||	j#j%d d < nL|r|j&|||f|}	n|j||f|\}	||	j#j$d d < ||	j#j%d d < qW | jd k	r:| jn| j'j(j)d }d }}| jdkr`d}| jdkrpd}| j*||| d
| j	kr|r|rt+t j,j-}	nt+t jjg g }	| jd k	r| jn| j'}| j.||	|d|||i  d S )NrV   rM   r   r   r,   r-   Tr   r   r.   rS   r   r   rU   g      ?g      ?rO   )r   Fr   ZDensity)rV   rM   )rV   rM   )r   r   )/rF   collectionsZPolyCollectionr   r   r   r   r8   r9   r1   r   r>   r   r   r_   r   r   r   r   r   r=   r{   r   r   r   r   r   r   r   r   r   r   r   rA   rD   r   r,   r-   r   r&   rG   r   r   r   r   r   rT   ) r4   r   r   r   r   rM   r    r   r   rL   Zsubsetsr   r   r   Zsticky_densityZsticky_supportrS   r   r   r   rO   r   rv   r   r   r   Z	fill_fromr   rP   r   r   rK   r6   r6   r7   plot_univariate_density}  s    






 z,_DistributionPlotter.plot_univariate_densityc       *   	      s  |j  }tf |}tjddh s(d}jj }i i  }}x$jdddD ]\}}|j }|ddg }djkr|d }nd }|ddg j }tdd	 |D s|j	 j rd
}|rNt
j|t qN|d |d f}||d|i\}}|\}}jdr
tjd|}jdr"tjd|}||f}|rD|t|t| 9 }t|j }|||< |||< qNW |d krrd}ttrtj|dn$tdk stdkrtd|rjt|j   fdd|D }nfdd|j D }jd kr|d krdn|}n"jjg |d\}|j }|j  djkrxdD ]0}||krL| d}t
j|t |j | qLW nt|ddh@ } |r|  rj!|}!|!|d< | r|  r|g|d< |j dd }!t|!t"rt#|!dd}!|!d k	r|!|d< xjdD ]\}}"d|krPj$|d }|rFj!||d< n
|g|d< j%|}#|rh|#j&}$n|#j'}$t|j }||krq|| }|| \}}|j dd }%|$|||fd|| i|}&djkr|&j(d j)|% |r|
d kri n|
}
|#j*j+|&|	|#f|
 qW jd k	r$jnj,j-j.d }#j/|# djkr|ri }'|rft0t1j2j3}(nt0t1j4j5g g }(jd k	rjnj,})j6|)|(|ddd|'i  d S )Nr,   r-   Fr.   T)r   r/   c             s   s   | ]}t j|d V  qdS )r   N)r   r   )rl   r,   r6   r6   r7   	<genexpr>L  s    z>_DistributionPlotter.plot_bivariate_density.<locals>.<genexpr>zfDataset has 0 variance; skipping density estimate. Pass `warn_singular=False` to disable this warning.r   r   r   zlevels must be in [0, 1]c                s   i | ]
} |qS r6   r6   )rl   r~   )common_levelsr6   r7   r   w  s    z?_DistributionPlotter.plot_bivariate_density.<locals>.<dictcomp>c                s   i | ]\}}j | |qS r6   )rf   )rl   r~   d)rB   r4   r6   r7   r   y  s   r   )rS   r   rr   z* parameter ignored when using hue mapping.)r  labelrB   r   )r   rr   )7rY   r	   r9   r1   r   r   r   r   r  Zisnar   r   r   r   r_   r   r   r   r   rE   r   rn   r   r   r   rf   listrd   r   r   r   r   r=   rz   r  r   rA   r   ZcontourfZcontourr  Z	set_labelr   r	  r&   rG   r   r   r   rF   r   r   r   r   rT   )*r4   r   rM   rB   r
  rS   r    r!   r   r"   r#   r   Zcontour_kwsr   r   r   Zsupportsr   r   r   r/   Zvariancer   r   r   ry   yyr   Zdraw_levelsr   r   paramZcoloring_givenr   rv   r   Zcontour_funcr  ZcsetrP   rL   rK   r6   )r  rB   r4   r7   plot_bivariate_density"  s    
















 
z+_DistributionPlotter.plot_bivariate_densityc          	   K   s  t f |}tddd}|| j |d< x
| jddddD ]\}}|j }|jrPq8|| j }|jdd }	|||	d	\}
}|j }d| jkr| j	|d |d
< | j
| jrtjd|}tj |d< | jdkr||
f}d}n|
|f}d}|jdkrt|}nd}| j|}|j||\}t|j|}d|f|d d < q8W | jd k	rD| jn| jjjd }|jj }
d }}| jdkrt|
}| jdkr|
}| j||| d| jkr|rttjjg g }|jdd}| jd k	r| jn| j}| j||ddd ||i  d S )Nz
steps-postz	steps-pre)r,   r-   r   r.   T)r   r   r/   )r/   rS   r   r   r,   r-   r   r   r   rO   F)r   rH   r>   r   r   r  r   rY   r1   rA   r   r_   r   r   r   r   r   r   getattrr   r   r&   rG   r   r   r   r   rF   r   r   rT   )r4   r   r    r   r   Z
drawstylesr   r   r   r/   r   valsrP   Z	plot_argsZstat_variableZtop_edger   rL   r   r   r   rO   rK   r6   r6   r7   plot_univariate_ecdf  sV    






 
z)_DistributionPlotter.plot_univariate_ecdfc          
   K   sz  t |tjj}| jd kr*|jdd|d< n0| jjg g f|\}|jd|j |d< |j  x| j	ddD ]\}}| j
|}|jdd |r|j \}	}
d| jkr|
|d 7 }
d	| jkr|	|d 7 }	|j|	|
d
 d| jkr|jdd  |jdd  d| jkr| j|d||| d	| jkr2| j|d	||| | j| d| jkrj|rjttjjg g }| j||ddd di i  qjW d S )NrS   r   T)r   r   r   r,   rk   r-   )r,   r-   r.   cF)r   rF   r   r   r   r=   r   r   r   r   r   rZ   Zmarginsr1   _plot_single_rugr   r   rT   )r4   heightexpand_marginsr    r[   r   r   r   r   ZxmargZymargZlegend_artistr6   r6   r7   plot_rug%  s8    





z_DistributionPlotter.plot_rugc             C   s   || }t |}| j|r&tjd|}d| jkr@| j|d }nd}|dkr~tj|j|j	}	tj
tj|dtjd|g|g}
|dkrtj|j	|j}	tj
tjd|g|tj|dg}
|
j|ddg}|jt|f|	|d| |j|dk|dkd	 dS )
z*Draw a rugplot along one axis of the plot.r   r.   Nr,   rk   r   r-   )r   rr   )ZscalexZscaley)r   r   r_   r   r1   rA   txZblended_transform_factoryr   Z	transAxesZcolumn_stackrepeatZtileZreshapeZadd_collectionr   r   )r4   r   r   r  r   r[   Zvectorr   rr   ZtransZxy_pairsZ	line_segsr6   r6   r7   r  P  s&    

z%_DistributionPlotter._plot_single_rug)r,   r-   r.   r/   )T)__name__
__module____qualname__	semanticsZwide_structureZflat_structurer3   propertyr:   r>   r?   rT   rD   rf   rz   r}   r   r   r   r  r  r  r  r  r  __classcell__r6   r6   )r5   r7   r+   b   s8   
	

H
;    ! & >F+r+   c               @   s   e Zd Zejd ZdS )_DistributionFacetPlotterr   r   N)r   r   )r"  r#  r$  r+   r%  r6   r6   r6   r7   r(  x  s   r(  r   r   FTr   rW   ) r,   r-   r.   r/   r   r   r   binranger|   r   r   r   r   rN   rM   r   r(   r   r   r
  r  r  r!   r"   r#   palette	hue_orderhue_normrS   r   r    r   c       $      K   s   t | t jt d}"|"j|||d | d kr4tj } |"js>| S |"j| |d |	d kr\|"j }	t	|||||	|
d}#|"j
r|"jf |||||||||||#|d|! n(|"jf |||||||||||#d|! | S )N)r0   r1   )r*  ordernorm)r   )r   r   r   r)  r|   r   )r   rN   rM   r   r   r   r(   r   rS   r    r   r   )r   r   r
  r  r  rS   r    r!   r"   r#   r   )r+   get_semanticslocalsmap_huepltgcar?   _attachr}   rH   r:   r   r  )$r0   r,   r-   r.   r/   r   r   r   r)  r|   r   r   r   r   rN   rM   r   r(   r   r   r
  r  r  r!   r"   r#   r*  r+  r,  rS   r   r    r   kwargspr   r6   r6   r7   r     s^    
aM  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
disrete 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 is constistute 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$   r7  r8     rh   r   g?Zscott)!r-   shadeverticalkernelbwgridsizer   r\   r    r   shade_lowestr!   r"   r#   r   r/   r.   r*  r+  r,  r   r   r   rB   r
  	bw_method	bw_adjustr   rS   rM   r0   data2r   c   !   (      K   s  | d k	rH| }| d ko(|d k	o(t j|dk}#|#r8d}$|} nd}$tj|$t |rfd}$tj|$t ||  } }|d k	rd| d}$tj|$t |}|d k	rd}$tj|$t |d k	r|rd}d	| d
}$tj|$t |"jd|}|d k	r|}t|tjt	 d}%|%j
|||d |d krtj }|%js$|S t||||||
d}&|%j|ddg|d |%jr|"j }'|d k	rn||'d< |%jf |||||	|!|&d|' n(|%jf |||||	||!||||&d|" |S )Nr   z/Use `x` and `y` rather than `data` `and `data2`z;The `data2` param is now named `y`; please update your codez|The `vertical` parameter is deprecated and will be removed in a future version. Assign the data to the `y` variable instead.zPThe `bw` parameter is deprecated in favor of `bw_method` and `bw_adjust`. Using zV for `bw_method`, but please see the docs for the new parameters and update your code.zFSupport for alternate kernels has been removed. Using Gaussian kernel.r   zG`shade_lowest` is now deprecated in favor of `thresh`. Setting `thresh=z`, but please update your code.Zn_levels)r0   r1   )r*  r-  r.  )r@  rA  r>  r   r\   r   numericr   )allowed_typesr   rS   )r   r   r   rM   r    r   r   )r   rM   rB   r
  r    rS   r   r!   r"   r#   r   )r_   ndimr   r   FutureWarningr   r=   r+   r/  r0  r1  r2  r3  r?   rH   r4  r:   rY   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   rB   r
  r@  rA  r   rS   rM   r0   rB  r   r5  Zx_passed_as_datar   r6  r   r   r6   r6   r7   r   [  s    !




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, analagous 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.xy}
shade : bool
    Alias for ``fill``. Using ``fill`` is recommended.
vertical : bool
    Orientation parameter.

    .. deprecated:: 0.11.0
       specify orientation by assigning the ``x`` or ``y`` variables.

kernel : str
    Function that defines the kernel.

    .. deprecated:: 0.11.0
       support for non-Gaussian kernels has been removed.

bw : str, number, or callable
    Smoothing parameter.

    .. deprecated:: 0.11.0
       see ``bw_method`` and ``bw_adjust``.

gridsize : int
    Number of points on each dimension of the evaluation grid.
{params.kde.cut}
{params.kde.clip}
{params.dist.legend}
{params.kde.cumulative}
shade_lowest : bool
    If False, the area below the lowest contour will be transparent

    .. deprecated:: 0.11.0
       see ``thresh``.

{params.dist.cbar}
{params.dist.cbar_ax}
{params.dist.cbar_kws}
{params.core.ax}
weights : vector or key in ``data``
    If provided, weight the kernel density estimation using these values.
{params.core.hue}
{params.core.palette}
{params.core.hue_order}
{params.core.hue_norm}
{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.
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.
{params.kde.bw_method}
{params.kde.bw_adjust}
{params.dist.log_scale}
{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.core.data}
warn_singular : bool
    If True, issue a warning when trying to estimate the density of data
    with zero variance.
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

Z
proportion)r,   r-   r.   r/   r   complementaryr*  r+  r,  r   r    r   c            K   sv   t | t jt d}|j|||	d |d kr4tj }|jsBtd|j||
d t	||d}|j
f ||d| |S )N)r0   r1   )r*  r-  r.  z(Bivariate ECDF plots are not implemented)r   )r   rG  )r   r    )r+   r/  r0  r1  r2  r3  r:   NotImplementedErrorr4  rH   r  )r0   r,   r-   r.   r/   r   rG  r*  r+  r,  r   r    r   r5  r6  r   r6   r6   r7   r     s"    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   r0   r-   r.   r*  r+  r,  r  r    ac            K   s   |d k	rd}t j|t |} ~|d k	r6d}t j|t |jd|dkr`d |  } }d}t j|t d }t|tjt d}|j|||	d |d krtj	 }|j
| |j||
|f| |S )Nz=The `a` parameter is now called `x`. Please update your code.zlThe `axis` variable is no longer used and will be removed. Instead, assign variables directly to `x` or `y`.r;  r-   zwUsing `vertical=True` to control the orientation of the plot  is deprecated. Instead, assign the data directly to `y`. )r0   r1   )r*  r-  r.  )r   r   rF  r=   r+   r/  r0  r1  r2  r3  r4  r  )r,   r  r   r   r0   r-   r.   r*  r+  r,  r  r    rI  r5  r   r/   r6  r6   r6   r7   r     s,    

a  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 unobstrusive way.

Parameters
----------
{params.core.xy}
height : number
    Proportion of axes extent covered by each rug element.
axis : {{"x", "y"}}
    Axis to draw the rug on.

    .. deprecated:: 0.11.0
       specify axis by assigning the ``x`` or ``y`` variables.

{params.core.ax}
{params.core.data}
{params.core.hue}
{params.core.palette}
{params.core.hue_order}
{params.core.hue_norm}
expand_margins : bool
    If True, increase the axes margins by the height of the rug to avoid
    overlap with other elements.
legend : bool
    If False, do not add a legend for semantic variables.
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   r/   kindrugrug_kwsr   r    r*  r+  r,  rS   col_wrap	row_order	col_orderr  aspect	facet_kwsc      '      K   sH  t | t jt d}|j|||d tddddg| d|kr^dj|}tj|t |j	d x6dD ].}||j
krd|j
| d krdd| d|j
|< qdW |jj|j
d}|jd d |jj  f }|j
jd
d }|j
jd	d }|d kri }tf ||||||||d|}|dkrddg}nd }|j|||
d |js<|S ||d< |dkr|j }i } t| tjt i }!x&| j D ]\}"}#|j	|"|#|!|"< qvW |!d d kr|j |!d< |!|d< |jd| |jrt||jt |jf | nt||jt |jf | n,|dkr|j }$i } t| tjt  i }!x&| j D ]\}"}#|$j	|"|#|!|"< q6W |!|$d< ||$d< |jrt|$|j!t  |j!f |$ nt|$|j"t  |j"f |$ n|dkr0|j }%i }!i } t| t#jt$ x&| j D ]\}"}#|%j	|"|#|!|"< qW |!|%d< ||%d< |jr(t|%|j%t$ |j%f |% nt&d|rx|	d krDi }	t|	|j't( d|	d< |d k	rl||	d< |j'f |	 |j)|j
jd|j*j+d j, |j
jd|j*j+d j- d |j.  |j/  | d k	r |d k	s|d k	r t0| t1j2st1j2| } t1j3| |j4|j4jj5| j ddd|_4n$dd |j
j D }&|jj|&d|_4|S ) N)r0   r1   )r*  r-  r.  rK  r)   r(   r*   r   zf`displot` is a figure-level function and does not accept the ax= paramter. You may wish to try {}plot.r   r   rv   )r   )r0   r   r   rN  rO  rP  r  rQ  rC  r   )rD  r   r    r|   r   rS   z(Bivariate ECDF plots are not implementedFr,   r   r-   )Zx_varZy_varT)Z
left_indexZright_indexc             S   s*   i | ]"\}}|d kr d| dn||qS )Nrv   r6   )rl   r~   r   r6   r6   r7   r   7	  s   zdisplot.<locals>.<dictcomp>)r   r   )6r(  r/  r0  r1  r   formatr   r   r   r=   r1   r   r   r   r   Z
duplicatedr   r   r4  r?   rY   r   r
   r3   r   r   r}   rZ   r:   r   r  r	   r   r  r  r   r   r  rH  r  r   Zset_axis_labelsrG   r   Z
get_xlabelZ
get_ylabelZ
set_titlesZtight_layoutrE   r   r   merger0   
difference)'r0   r,   r-   r.   r   r   r/   rK  rL  rM  r   r    r*  r+  r,  rS   rN  rO  rP  r  rQ  rR  r5  r6  r   r   Z	grid_dataZcol_nameZrow_namert   rD  hist_kwsZestimate_defaultsr   r   Zdefault_valr   Zecdf_kwsZ	wide_colsr6   r6   r7   r     s    









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   sn   t j| } t| dk rdS dtj|  t| d  }|dkrLtt j| jS tt j| j	 | j
  | S dS )z;Calculate number of hist bins using Freedman-Diaconis rule.rk   r   rh   r   NgUUUUUU?)r_   r`   r   r   Ziqrro   sqrtsizeceilr   r   )rI  rw   r6   r6   r7   _freedman_diaconis_bins	  s    
rZ  c       !         st  |r| rd}nd}d| }t j|t |dkr8tj }t|}|dkrdt| drd| j}|dk	rdd}|dk	rp|} tj	| t
} | jdkr| j } t| } |p|p dk	}|dkri n|j }|dkri n|j }|dkri n|j }|	dkri n|	j }	|
dkr<|r|jd| j \}n|j| j d\}|j }
|j  |dk	r|rV||d	< n.|rf||d	< n|rv||d	< n r||	d	< |r |dkrtt| d
}|jdd |jd| |rdnd}|jd|
}|j| |f||d| ||
kr ||d< |r<|jd|
}t| f|||d| ||
kr<||d< |r|jd|
}|rXdnd}t| f|||d| ||
kr||d<  dk	rN fdd}|	jdd}|	jdd}|	jdd}|	jdtj tjf}tj| j | jdd }t| ||||} j | ||} |r$| | }} |j|| fd|i|	 |dkrN||	d< |rp|rf|j!| n
|j"| |S )a  DEPRECATED: Flexibly plot a univariate distribution of observations.

    .. warning::
       This function is deprecated and will be removed in a future version.
       Please adapt your code to use one of two new functions:

       - :func:`displot`, a figure-level function with a similar flexibility
         over the kind of plot to draw
       - :func:`histplot`, an axes-level function for plotting histograms,
         including with kernel density smoothing

    This function combines the matplotlib ``hist`` function (with automatic
    calculation of a good default bin size) with the seaborn :func:`kdeplot`
    and :func:`rugplot` functions. It can also fit ``scipy.stats``
    distributions and plot the estimated PDF over the data.

    Parameters
    ----------
    a : Series, 1d-array, or list.
        Observed data. If this is a Series object with a ``name`` attribute,
        the name will be used to label the data axis.
    bins : argument for matplotlib hist(), or None, optional
        Specification of hist bins. If unspecified, as reference rule is used
        that tries to find a useful default.
    hist : bool, optional
        Whether to plot a (normed) histogram.
    kde : bool, optional
        Whether to plot a gaussian kernel density estimate.
    rug : bool, optional
        Whether to draw a rugplot on the support axis.
    fit : random variable object, optional
        An object with `fit` method, returning a tuple that can be passed to a
        `pdf` method a positional arguments following a grid of values to
        evaluate the pdf on.
    hist_kws : dict, optional
        Keyword arguments for :meth:`matplotlib.axes.Axes.hist`.
    kde_kws : dict, optional
        Keyword arguments for :func:`kdeplot`.
    rug_kws : dict, optional
        Keyword arguments for :func:`rugplot`.
    color : matplotlib color, optional
        Color to plot everything but the fitted curve in.
    vertical : bool, optional
        If True, observed values are on y-axis.
    norm_hist : bool, optional
        If True, the histogram height shows a density rather than a count.
        This is implied if a KDE or fitted density is plotted.
    axlabel : string, False, or None, optional
        Name for the support axis label. If None, will try to get it
        from a.name if False, do not set a label.
    label : string, optional
        Legend label for the relevant component of the plot.
    ax : matplotlib axis, optional
        If provided, plot on this axis.

    Returns
    -------
    ax : matplotlib Axes
        Returns the Axes object with the plot for further tweaking.

    See Also
    --------
    kdeplot : Show a univariate or bivariate distribution with a kernel
              density estimate.
    rugplot : Draw small vertical lines to show each observation in a
              distribution.

    Examples
    --------

    Show a default plot with a kernel density estimate and histogram with bin
    size determined automatically with a reference rule:

    .. plot::
        :context: close-figs

        >>> import seaborn as sns, numpy as np
        >>> sns.set_theme(); np.random.seed(0)
        >>> x = np.random.randn(100)
        >>> ax = sns.distplot(x)

    Use Pandas objects to get an informative axis label:

    .. plot::
        :context: close-figs

        >>> import pandas as pd
        >>> x = pd.Series(x, name="x variable")
        >>> ax = sns.distplot(x)

    Plot the distribution with a kernel density estimate and rug plot:

    .. plot::
        :context: close-figs

        >>> ax = sns.distplot(x, rug=True, hist=False)

    Plot the distribution with a histogram and maximum likelihood gaussian
    distribution fit:

    .. plot::
        :context: close-figs

        >>> from scipy.stats import norm
        >>> ax = sns.distplot(x, fit=norm, kde=False)

    Plot the distribution on the vertical axis:

    .. plot::
        :context: close-figs

        >>> ax = sns.distplot(x, vertical=True)

    Change the color of all the plot elements:

    .. plot::
        :context: close-figs

        >>> sns.set_color_codes()
        >>> ax = sns.distplot(x, color="y")

    Pass specific parameters to the underlying plot functions:

    .. plot::
        :context: close-figs

        >>> ax = sns.distplot(x, rug=True, rug_kws={"color": "g"},
        ...                   kde_kws={"color": "k", "lw": 3, "label": "KDE"},
        ...                   hist_kws={"histtype": "step", "linewidth": 3,
        ...                             "alpha": 1, "color": "g"})

    z<`kdeplot` (an axes-level function for kernel density plots).z3`histplot` (an axes-level function for histograms).z`distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or Nr   Tr   r   r  2   rO   g?r   Z
horizontalr;  rS   )orientationrS   )r;  r   rS   r-   r,   )r   r   rS   c                s    j | f S )N)pdf)r,   )fitr$   r6   r7   r]  
  s    zdistplot.<locals>.pdfz#282828r>  r9  r   rh   r\   )Zddof)#r   r   rF  r2  r3  r8   hasattrr   r_   r`   floatrE  r   r   rY   r   Zmeanr   r   r   rZ  rZ   r=   r)   r   r   r   r   Zgaussian_kdeZscotts_factorZstdr   r^  Z
set_ylabelZ
set_xlabel)!rI  r   r)   r(   rL  r^  rV  r   rM  Zfit_kwsrS   r;  Z	norm_histZaxlabelr  r   r,   Zaxes_level_suggestionr   Zlabel_axr   r\  Z
hist_colorZ	kde_colorZ	rug_colorr   r]  Z	fit_colorr>  r   r\   r=  r-   r6   )r^  r$   r7   r   	  s     
















)N)N)N)N)N)NNTTFNNNNNNFFNNNN)B__doc__Znumbersr   	functoolsr   r   r   Znumpyr_   Zpandasr   Z
matplotlibrF   Zmatplotlib.pyplotZpyplotr2  Zmatplotlib.transformsZ
transformsr   Zmatplotlib.colorsr   Zmatplotlib.collectionsr   Zscipyr   Z_corer   Z_statisticsr	   r
   r   Zaxisgridr   r   utilsr   r   r   r   r   Zpalettesr   Zexternalr   Z_decoratorsr   Z_docstringsr   r   __all__rH   Z_dist_paramsZfrom_nested_componentsZfrom_function_paramsr3   Z_param_docsr+   r(  r   rS  r   r   r   r   rZ  r   r6   r6   r6   r7   <module>   s   



	           
 D  ([b
 }	   