
    6Dh07                         S SK JrJr  S SKJr  S SKJr  \R                  " S5      r\R                  " S5      r	\R                  " S5      r
\R                  " S5      rSrS	rS
 rSSSS\SSS4S jr " S S\5      rg)    )
exceptionsoptional_imports)utils)
graph_objsnumpypandasscipyzscipy.statszprobability densityprobabilityc                 p   [         4n[        (       a  U[        R                  4-  n[        (       a(  U[        R                  R
                  R                  4-  n[        U S   U5      (       d  [        R                  " S5      eSnX;  a  [        R                  " S5      e[        (       d  [        S5      eg)z
Distplot-specific validations

:raises: (PlotlyError) If hist_data is not a list of lists
:raises: (PlotlyError) If curve_type is not valid (i.e. not 'kde' or
    'normal').
r   zOops, this function was written to handle multiple datasets, if you want to plot just one, make sure your hist_data variable is still a list of lists, i.e. x = [1, 2, 3] -> x = [[1, 2, 3]])kdenormalz/curve_type must be defined as 'kde' or 'normal'z,FigureFactory.create_distplot requires scipyN)listnpndarraypdcoreseriesSeries
isinstancer   PlotlyErrorr	   ImportError)	hist_data
curve_typehist_data_types
curve_optss       Q/var/www/html/env/lib/python3.13/site-packages/plotly/figure_factory/_distplot.pyvalidate_distplotr      s     gO	rBJJ=(	rBGGNN1133ilO44$$+
 	
 #J#$$@
 	
 5HII           ?r   NTc
                    Uc  / nUc  / n[        X5        [        R                  " X5        [        U[        [
        45      (       a  U/[        U 5      -  n/ n
U(       a2  [        U UUUUUUUU5	      R                  5       nU
R                  U5        U(       aZ  US:X  a"  [        U UUUUUUUU5	      R                  5       nO![        U UUUUUUUU5	      R                  5       nU
R                  U5        U	(       au  [        U UUUUUUUU5	      R                  5       nU
R                  U5        [        R                  " SS[        SS9[        SS/SS	S
9[        SS/SSS9[        SS/SSS	S9S9nO5[        R                  " SS[        SS9[        SS/SS	S
9[        SS/SSS9S9n[!        U
/ 5      n
[        R"                  " XS9$ )a  
Function that creates a distplot similar to seaborn.distplot;
**this function is deprecated**, use instead :mod:`plotly.express`
functions, for example

>>> import plotly.express as px
>>> tips = px.data.tips()
>>> fig = px.histogram(tips, x="total_bill", y="tip", color="sex", marginal="rug",
...                    hover_data=tips.columns)
>>> fig.show()


The distplot can be composed of all or any combination of the following
3 components: (1) histogram, (2) curve: (a) kernel density estimation
or (b) normal curve, and (3) rug plot. Additionally, multiple distplots
(from multiple datasets) can be created in the same plot.

:param (list[list]) hist_data: Use list of lists to plot multiple data
    sets on the same plot.
:param (list[str]) group_labels: Names for each data set.
:param (list[float]|float) bin_size: Size of histogram bins.
    Default = 1.
:param (str) curve_type: 'kde' or 'normal'. Default = 'kde'
:param (str) histnorm: 'probability density' or 'probability'
    Default = 'probability density'
:param (bool) show_hist: Add histogram to distplot? Default = True
:param (bool) show_curve: Add curve to distplot? Default = True
:param (bool) show_rug: Add rug to distplot? Default = True
:param (list[str]) colors: Colors for traces.
:param (list[list]) rug_text: Hovertext values for rug_plot,
:return (dict): Representation of a distplot figure.

Example 1: Simple distplot of 1 data set

>>> from plotly.figure_factory import create_distplot

>>> hist_data = [[1.1, 1.1, 2.5, 3.0, 3.5,
...               3.5, 4.1, 4.4, 4.5, 4.5,
...               5.0, 5.0, 5.2, 5.5, 5.5,
...               5.5, 5.5, 5.5, 6.1, 7.0]]
>>> group_labels = ['distplot example']
>>> fig = create_distplot(hist_data, group_labels)
>>> fig.show()


Example 2: Two data sets and added rug text

>>> from plotly.figure_factory import create_distplot
>>> # Add histogram data
>>> hist1_x = [0.8, 1.2, 0.2, 0.6, 1.6,
...            -0.9, -0.07, 1.95, 0.9, -0.2,
...            -0.5, 0.3, 0.4, -0.37, 0.6]
>>> hist2_x = [0.8, 1.5, 1.5, 0.6, 0.59,
...            1.0, 0.8, 1.7, 0.5, 0.8,
...            -0.3, 1.2, 0.56, 0.3, 2.2]

>>> # Group data together
>>> hist_data = [hist1_x, hist2_x]

>>> group_labels = ['2012', '2013']

>>> # Add text
>>> rug_text_1 = ['a1', 'b1', 'c1', 'd1', 'e1',
...       'f1', 'g1', 'h1', 'i1', 'j1',
...       'k1', 'l1', 'm1', 'n1', 'o1']

>>> rug_text_2 = ['a2', 'b2', 'c2', 'd2', 'e2',
...       'f2', 'g2', 'h2', 'i2', 'j2',
...       'k2', 'l2', 'm2', 'n2', 'o2']

>>> # Group text together
>>> rug_text_all = [rug_text_1, rug_text_2]

>>> # Create distplot
>>> fig = create_distplot(
...     hist_data, group_labels, rug_text=rug_text_all, bin_size=.2)

>>> # Add title
>>> fig.update_layout(title='Dist Plot') # doctest: +SKIP
>>> fig.show()


Example 3: Plot with normal curve and hide rug plot

>>> from plotly.figure_factory import create_distplot
>>> import numpy as np

>>> x1 = np.random.randn(190)
>>> x2 = np.random.randn(200)+1
>>> x3 = np.random.randn(200)-1
>>> x4 = np.random.randn(210)+2

>>> hist_data = [x1, x2, x3, x4]
>>> group_labels = ['2012', '2013', '2014', '2015']

>>> fig = create_distplot(
...     hist_data, group_labels, curve_type='normal',
...     show_rug=False, bin_size=.4)


Example 4: Distplot with Pandas

>>> from plotly.figure_factory import create_distplot
>>> import numpy as np
>>> import pandas as pd

>>> df = pd.DataFrame({'2012': np.random.randn(200),
...                    '2013': np.random.randn(200)+1})
>>> fig = create_distplot([df[c] for c in df.columns], df.columns)
>>> fig.show()
r   overlayclosestreversed)
traceorderg        r   y2F)domainanchorzerolinegffffff?   free)r&   r'   positionr   g      ?x1)r&   r'   dtickshowticklabels)barmode	hovermodelegendxaxis1yaxis1yaxis2)r/   r0   r1   r2   r3   )datalayout)r   r   validate_equal_lengthr   floatintlen	_Distplot	make_histappendmake_normalmake_kdemake_rugr   LayoutdictsumFigure)r   group_labelsbin_sizer   colorsrug_texthistnorm	show_hist
show_curveshow_rugr5   histcurverugr6   s                  r   create_distplotrP   2   s   v ~i,		8(UCL)):I.D

 )+ 	 	D!
 km  
 hj  	E

 (* 	 	C"":.Sz$Gay#F4yQuU
 "":.Sz$GQxE
 tR=D$66r   c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
r;   i
  z7
Refer to TraceFactory.create_distplot() for docstring
c
                    Xl         X l        X0l        X@l        Xl        Xl        [        U5      U l        U(       a  Xpl        OS /U R                  -  U l        / U l	        / U l
        U(       a  X`l        O	/ SQU l        S /U R                  -  U l        S /U R                  -  U l        U R                    HQ  n
U R                  R                  [        U
5      S-  5        U R                  R                  [!        U
5      S-  5        MS     g )N)
zrgb(31, 119, 180)zrgb(255, 127, 14)zrgb(44, 160, 44)zrgb(214, 39, 40)zrgb(148, 103, 189)zrgb(140, 86, 75)zrgb(227, 119, 194)zrgb(127, 127, 127)zrgb(188, 189, 34)zrgb(23, 190, 207)r   )r   rI   rE   rF   rJ   rK   r:   trace_numberrH   startendrG   curve_xcurve_yr=   minmax)selfr   rI   rE   rF   r   rG   rH   rJ   rK   traces              r   __init___Distplot.__init__  s     # ( "$	N$M!FT%6%66DM
 KDK v 1 11v 1 11^^EJJc%j3./HHOOCJ,- $r   c                    S/U R                   -  n[        U R                   5       H  n[        SU R                  U   SSU R                  U R
                  U   U R
                  U   [        U R                  U[        U R                  5      -     S9S[        U R                  U   U R                  U   U R                  U   S9SS	9X'   M     U$ )
zt
Makes the histogram(s) for FigureFactory.create_distplot().

:rtype (list) hist: list of histogram representations
N	histogramr,   y1colorF)rT   rU   sizegffffff?)typexxaxisyaxisrI   namelegendgroupmarkerautobinxxbinsopacity)rS   rangerB   r   rI   rE   rG   r:   rT   rU   rF   )rZ   rM   indexs      r   r<   _Distplot.make_hist?  s     v)))4,,-E ..'&&u- --e4$++ec$++6F.F"GH**U+u-
 DK .$ r   c                 X   S/U R                   -  n[        U R                   5       H  n[        S5       Vs/ s H7  nU R                  U   X0R                  U   U R                  U   -
  -  S-  -   PM9     snU R                  U'   [
        R                  U R                  U   5      " U R                  U   5      U R                  U'   U R                  [        :X  d  M  U R                  U==   U R                  U   -  ss'   M     [        U R                   5       H  n[        SU R                  U   U R                  U   SSSU R                  U   U R                  U   U R                  (       a  SOS[        U R                  U[!        U R                  5      -     S	9S
9
X'   M     U$ s  snf )z
Makes the kernel density estimation(s) for create_distplot().

This is called when curve_type = 'kde' in create_distplot().

:rtype (list) curve: list of kde representations
N  scatterr,   r`   linesFTra   
rd   re   yrf   rg   moderh   ri   
showlegendrj   )rS   rn   rT   rU   rV   scipy_statsgaussian_kder   rW   rI   ALTERNATIVE_HISTNORMrF   rB   rE   rJ   rG   r:   )rZ   rN   ro   re   s       r   r?   _Distplot.make_kde[  s~    ***4,,-E s##A 

5!A%4::e;L)L$MPS$SS##DLL #.":":4>>%;P"QU##DLL }} 44U#t}}U';;# . 4,,-E,,u%,,u%&&u- --e4$(NN5$++ec$++6F.F"GHEL . 1#s   >F'c                    S/U R                   -  nS/U R                   -  nS/U R                   -  n[        U R                   5       GH	  n[        R                  R	                  U R
                  U   5      u  X$'   X4'   [        S5       Vs/ s H7  nU R                  U   XPR                  U   U R                  U   -
  -  S-  -   PM9     snU R                  U'   [        R                  R                  U R                  U   X$   X4   S9U R                  U'   U R                  [        :X  d  M  U R                  U==   U R                  U   -  ss'   GM     [        U R                   5       H  n[        SU R                  U   U R                  U   SSSU R                  U   U R                  U   U R                   (       a  SOS	[        U R"                  U[%        U R"                  5      -     S
9S9
X'   M     U$ s  snf )z
Makes the normal curve(s) for create_distplot().

This is called when curve_type = 'normal' in create_distplot().

:rtype (list) curve: list of normal curve representations
Nrr   )locscalers   r,   r`   rt   FTra   ru   )rS   rn   ry   normfitr   rT   rU   rV   pdfrW   rI   r{   rF   rB   rE   rJ   rG   r:   )rZ   rN   meansdro   re   s         r   r>   _Distplot.make_normal  s    ***v)))Vd'''4,,-E%0%5%5%9%9$..:O%P"DK s##A 

5!A%4::e;L)L$MPS$SS##DLL #."2"2"6"6U#BI #7 #DLL }} 44U#t}}U';;# . 4,,-E,,u%,,u%&&u- --e4$(NN5$++ec$++6F.F"GHEL . 1#s   
>G7c                    S/U R                   -  n[        U R                   5       H  n[        SU R                  U   U R                  U   /[        U R                  U   5      -  SSSU R                  U   U R                  U   U R                  (       d  U R                  (       a  SOSU R                  U   [        U R                  U[        U R                  5      -     SS	9S
9X'   M     U$ )zc
Makes the rug plot(s) for create_distplot().

:rtype (list) rug: list of rug plot representations
Nrs   r,   r%   markersFTzline-ns-open)rb   symbol)rd   re   rv   rf   rg   rw   rh   ri   rx   textrj   )
rS   rn   rB   r   rE   r:   rJ   rK   rH   rG   )rZ   rO   ro   s      r   r@   _Distplot.make_rug  s     ft(((4,,-E..'%%e,-DNN54I0JJ&&u- --e4%)^^tED]]5)++ec$++.>&>?CJ ." 
r   )rF   rG   rV   rW   rU   rE   r   rI   rH   rK   rJ   rT   rS   N)__name__
__module____qualname____firstlineno____doc__r\   r<   r?   r>   r@   __static_attributes__ r   r   r;   r;   
  s#    ..`8"H&Pr   r;   )plotlyr   r   plotly.figure_factoryr   plotly.graph_objsr   
get_moduler   r   r	   ry   DEFAULT_HISTNORMr{   r   rP   objectr;   r   r   r   <module>r      s    / ' (   )  *##G,))-8 ) $ JJ U7pu ur   