
    hMh              (       *   d Z ddl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mZ 	 ddlZesJ dZn# e$ r dZY nw xY wddlmZ ddlmZ dd	lmZmZ g d
Z G d d          Z G d de          Z edCi d ed          d ed          d ed          d ed          d ed          d ed          d ed          d ed          d ed           d! ed"          d# ed$          d% ed&          d' ed(          d) ed*          d+ ed,          d- ed.          d/ ed0          d1 ed2          d3 ed4          d5 ed6          Ze                    e           dddddddd7dd8ddddddddddddd9d:dddddddddddddddd;'d<Z  ed=          j        dCi ee_         	 dDdddddddd9d:dddddddddddddddd8dddd>d?Z   ed@          j        dCi ee _         	 dDddddddddddddddAdBZ!dS )Ez9Plotting functions for linear models (broadly construed).    N)dedentTF   )utils)
algorithms)	FacetGrid_facet_docs)lmplotregplot	residplotc                   $    e Zd ZdZd Zd Zd ZdS )_LinearPlotterzBase class for plotting relational data in tidy format.

    To get anything useful done you'll have to inherit from this, but setup
    code that can be abstracted out should be put here.

    c                    || _         t          d |                                D                       }|r|t          d          |                                D ]\  }}t          |t                    r	||         }n,t          |t                    rt          j	        |          }n|}||j
        dk    rt          j        |          }t          j        |          dk    rd}t          |          t          | ||           dS )z,Extract variables from data or use directly.c                 8    g | ]}t          |t                    S  )
isinstancestr.0vs     R/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/seaborn/regression.py
<listcomp>z6_LinearPlotter.establish_variables.<locals>.<listcomp>%   s"    DDD!:a--DDD    Nz*Must pass `data` if using named variables.)r   r   zregplot inputs must be 1d)dataanyvalues
ValueErroritemsr   r   listnpasarrayshapesqueezendimsetattr)selfr   kwsany_stringsvarvalvectorerrs           r   establish_variablesz"_LinearPlotter.establish_variables    s   	 DDszz||DDDEE 	K4<IJJJ 		 	' 	'HC#s## cC&& C!fld&:&:F++wv""1 oo%D#v&&&&	' 	'r   c                       fd|D             }d |D             }t          j        t          j        d |D                       d          }|D ]+}t           |          }|t	           |||                    ,dS )z&Remove observations with missing data.c                 0    g | ]}t          |          S r   )getattr)r   r(   r%   s     r   r   z)_LinearPlotter.dropna.<locals>.<listcomp>:   s#    333sc""333r   c                     g | ]}||S Nr   r   s     r   r   z)_LinearPlotter.dropna.<locals>.<listcomp>;   s    111a1====r   c                 6    g | ]}t          j        |          S r   )pdnotnullr   s     r   r   z)_LinearPlotter.dropna.<locals>.<listcomp><   s     (E(E(E1A(E(E(Er   r   axisN)r   allcolumn_stackr/   r$   )r%   varsvalsnot_nar(   r)   s   `     r   dropnaz_LinearPlotter.dropna8   s    3333d333114111(E(E(E(E(EFFQOOO 	0 	0C$$$Cc3v;///	0 	0r   c                     t           r1   )NotImplementedError)r%   axs     r   plotz_LinearPlotter.plotB   s    !!r   N)__name__
__module____qualname____doc__r,   r<   r@   r   r   r   r   r      sK         ' ' '00 0 0" " " " "r   r   c                       e Zd ZdZ	 	 	 	 	 	 dd	Zed
             Zed             Zd ZddZ	d Z
d Zd Zd Zd Zd Zd Zd Zd Zd ZdS )_RegressionPlotterzPlotter for numeric independent variables with regression model.

    This does the computations and drawing for the `regplot` function, and
    is thus also used indirectly by `lmplot`.
    NciT_     r   Fc                    || _         |	| _        |dk    r|	n|| _        |
| _        || _        || _        || _        || _        || _        || _	        || _
        || _        || _        || _        || _        || _        || _        t#          |dk    ||||f          dk    rt%          d          |                     ||||||           |r|                     ddddd	           | j        %|                     | j        | j                  | _        | j        %|                     | j        | j                  | _        |5|t4          j        n|| _         |                     |          \  }}|| _        n| j        | _        t=          | j                  dk    rd
| _        | j        r9| j                                        | j                                         f| _!        d S d S )NrG   r   z&Mutually exclusive regression options.)xyunits	x_partial	y_partialrK   rL   rM   rN   rO   F)"x_estimatorrG   x_cin_bootseedscatterfit_regorderlogisticlowessrobustlogxtruncatex_jittery_jittercolorlabelsumr   r,   r<   rN   regress_outrK   rO   rL   r   meanbin_predictor
x_discretelenminmaxx_range)r%   rK   rL   r   rP   x_binsrQ   rT   rU   rG   rR   rM   rS   rV   rW   rX   rY   rZ   rN   rO   r[   r<   r\   r]   r^   r_   rd   s                              r   __init__z_RegressionPlotter.__init__L   s    '$,,BBD		
 	   

 	8VVT:;;a??EFFF 	  au+4	 	! 	K 	K 	K  	EKKS';DDD >%%%dfdn==DF>%%%dfdn==DF *5*=rww;D!%!3!3F!;!;J(DOO"fDO tv;;! DL < 	66::<<5DLLL	6 	6r   c                 >   | j         }|| j        }n<| j        t          j                            | |t          | j                            z   }| j        }|| j        }n<| j        t          j                            | |t          | j                            z   }||fS )z'Data where each observation is a point.)r\   rK   r   randomuniformre   r]   rL   )r%   x_jrK   y_jrL   s        r   scatter_dataz_RegressionPlotter.scatter_data   s     m;AA**C4c$&kkBBBAm;AA**C4c$&kkBBBA!tr   c                 X   | j         | j        }}t          t          j        |                    }g g }}|D ]}|||k             }|                     |          }|                    |           | j        |                    d           Ud}	| j        dk    rt          j        |          }
||
z
  ||
z   f}nZ| j	        | j	        ||k             }	t          j        || j        | j        |	| j                  }t          j        || j                  }|                    |           |||fS )z<Data with a point estimate and CI for each discrete x value.NsdfuncrR   rM   rS   )rd   rL   sortedr   uniquerP   appendrQ   stdrM   algo	bootstraprR   rS   r   rG   )r%   rK   rL   r:   pointscisr)   _yestrM   rr   _cibootss                r   estimate_dataz _RegressionPlotter.estimate_data   s:    1bill##" 	  	 C 18B""2&&CMM# y 

4    9$$B(C"H,CCz- $
18 4 N2040@26+1604		; ; ;E
  (5$)44C

3VS  r   c                     d}d}|D ];}t          | |          r)t          s"t          |                    |                    <dS )zICheck whether statsmodels is installed if any boolean options require it.)rW   rY   rX   zH`{}=True` requires statsmodels, an optional dependency, to be installed.N)r/   _has_statsmodelsRuntimeErrorformat)r%   optionsr+   options       r   _check_statsmodelsz%_RegressionPlotter._check_statsmodels   sZ    0X 	7 	7FtV$$ 7-= 7"3::f#5#5666	7 	7r   c                    |                                   |G| j        r| j        \  }}n||\  }}n|                                \  }}t	          j        ||d          }| j        }| j        dk    r|                     || j                  \  }}n| j	        r0ddl
m}	 ddlm}
 |                     ||	 |
                      \  }}n| j        rd}|                                 \  }}n_| j        r ddlm} |                     ||          \  }}n8| j        r|                     |          \  }}n|                     |          \  }}|d}nt/          j        ||d	          }|||fS )
zFit the regression model.Nd   r   r   )GLM)Binomial)family)RLMr5   )r   r[   rh   get_xlimr   linspacerG   rV   fit_polyrW   +statsmodels.genmod.generalized_linear_modelr   statsmodels.genmod.familiesr   fit_statsmodelsrX   
fit_lowessrY   &statsmodels.robust.robust_linear_modelr   rZ   fit_logxfit_fastr   )r%   r?   rh   gridx_minx_maxrG   yhat
yhat_bootsr   r   r   	err_bandss                r   fit_regressionz!_RegressionPlotter.fit_regression   s   !!! <} 1#|uu:#*LE55#%;;==LE5;ueS11DW :>>#}}T4:>>D**] 	3GGGGGG<<<<<<#33D#;C8::  4  G  GD**[ 		3B**JD$$[ 	3BBBBBB#33D#>>D**Y 	3#}}T22D**#}}T22D* :IIRa888IT9$$r   c                    d }t           j        t          j        t          | j                            | j        f         | j        }}t           j        t          j        t          |                    |f         }|                     |||                    }| j        |dfS t          j	        |||| j
        | j        | j                  j        }|                    |          j        }||fS )z9Low-level regression and prediction using linear algebra.c                 f    t           j                            |                               |          S r1   )r   linalgpinvdot_xr}   s     r   reg_funcz-_RegressionPlotter.fit_fast.<locals>.reg_func   s$    9>>"%%))"---r   Nrs   )r   c_onesre   rK   rL   r   rG   ry   rz   rR   rM   rS   T)r%   r   r   XrL   r   
beta_bootsr   s           r   r   z_RegressionPlotter.fit_fast   s    	. 	. 	. uRWS[[))4612DF1uRWSYY''-.xxA''7?:^Aq)1+/;*.*)-	4 4 4 56	 	
 XXj))+
Zr   c                     fd}| j         | j        }} |||          }| j        |dfS t          j        |||| j        | j        | j                  }||fS )z7Regression using numpy polyfit for higher-order trends.c                 V    t          j        t          j        | |                    S r1   )r   polyvalpolyfit)r   r}   r   rV   s     r   r   z-_RegressionPlotter.fit_poly.<locals>.reg_func  s#    :bjR77>>>r   Nrs   )rK   rL   rG   ry   rz   rR   rM   rS   )r%   r   rV   r   rK   rL   r   r   s    ``     r   r   z_RegressionPlotter.fit_poly  s    	? 	? 	? 	? 	? 	? vtv1x1~~7?:^Aq)1+/;*.*)-	4 4 4

 Zr   c                   	 ddl mc m	 t          j        t          j        t          | j                            | j        f         | j        }}t          j        t          j        t                              f         	fd} |||          }| j	        |dfS t          j        |||| j        | j        | j                  }||fS )z;More general regression function using statsmodels objects.r   Nc                    j         f}	 t          j                    5  t          d          r&t          j        dj                   g |j        R } || fi                                                               }d d d            n# 1 swxY w Y   nK# |$ rC t          j	        t                              }|                    t          j                   Y nw xY w|S )NPerfectSeparationWarningerror)PerfectSeparationErrorwarningscatch_warningshasattrsimplefilterr   fitpredictr   emptyre   fillnan)r   r}   err_classesr   r   kwargsmodelsmes       r   r   z4_RegressionPlotter.fit_statsmodels.<locals>.reg_func  sN   57K	",.. G Gs$>?? S -gs7STTT&R&RS5Q&R&R 5R226226688@@FFDG G G G G G G G G G G G G G G  " " "xD		**		"&!!!!!" Ks6   B A&BB BB BB AC$#C$rs   )statsmodels.tools.sm_exceptionstoolssm_exceptionsr   r   r   re   rK   rL   rG   ry   rz   rR   rM   rS   )
r%   r   r   r   r   rL   r   r   r   r   s
    ```     @r   r   z"_RegressionPlotter.fit_statsmodels  s    555555555uRWS[[))4612DF1uRWSYY''-.	 	 	 	 	 	 	 	 x1~~7?:^Aq)1+/;*.*)-	4 4 4

 Zr   c                 R    ddl m}  || j        | j                  j        \  }}||fS )z>Fit a locally-weighted regression, which returns its own grid.r   )rX   )*statsmodels.nonparametric.smoothers_lowessrX   rL   rK   r   )r%   rX   r   r   s       r   r   z_RegressionPlotter.fit_lowess2  s:    EEEEEEVDFDF++-
dTzr   c                    t           j        t          j        t          | j                            | j        f         | j        }}t           j        t          j        t          |                    t          j        |          f         }d }|                     |||                    }| j        |dfS t          j
        |||| j        | j        | j                  j        }|                    |          j        }||fS )zFit the model in log-space.c                     t           j        | d d df         t          j        | d d df                   f         } t           j                            |                               |          S )Nr   r   )r   r   logr   r   r   r   s     r   r   z-_RegressionPlotter.fit_logx.<locals>.reg_func=  sW    r!!!Q$x111a4!1!112B9>>"%%))"---r   Nrs   )r   r   r   re   rK   rL   r   r   rG   ry   rz   rR   rM   rS   r   )r%   r   r   rL   r   r   r   r   s           r   r   z_RegressionPlotter.fit_logx8  s    uRWS[[))4612DF1uRWSYY''56	. 	. 	. xxA''7?:^Aq)1+/;*.*)-	4 4 4 56	 	
 XXj))+
Zr   c                    t          j        | j                  }t          j        |          r7t          j        dd|dz             dd         }t          j        ||          }nt          j        |          }t          j        t           j        	                    ||                    }|t          j
        |d                                                   }||fS )z9Discretize a predictor by assigning value to closest bin.r   r      r   r5   )r   r    rK   isscalarr   
percentileravelabssubtractouterargmin)r%   binsrK   percentilesdistx_binneds         r   rc   z _RegressionPlotter.bin_predictorM  s    Jtv;t 	"+adQh77"=K=K00DD8D>>Dvbk''40011	$Q///06688~r   c                 t   |                                 }||z
  }||                                 z
  }t          j        |         }||                    t          j                            |                              |                    z
  }t          j        ||z                                 |j                  S )z+Regress b from a keeping a's original mean.)	rb   r   r   r   r   r   r    reshaper!   )r%   aba_meana_primes        r   ra   z_RegressionPlotter.regress_out[  s    JLE!HaeeBINN1--11!44555z'F*++33AG<<<r   c                    | j         r| j        |d<   n
| j        |d<   | j        A|                    g g           \  }|                                }|                                 n| j        }t          j                            t          j        j	        
                    |                    }|                    d|           |                    d|           | j         r|                     ||           | j        r|                     ||           t          | j        d          r|                    | j        j                   t          | j        d          r!|                    | j        j                   dS dS )zDraw the full plot.r_   Nr^   name)rT   r_   r^   r@   	get_colorremovemplcolorsrgb2hexcolorConverterto_rgb
setdefaultscatterplotrU   lineplotr   rK   
set_xlabelr   rL   
set_ylabel)r%   r?   scatter_kwsline_kwslinesr^   s         r   r@   z_RegressionPlotter.plotd  si    < 	+#':K   $
HW :WWR__FEOO%%ELLNNNNJE 
""3:#<#C#CE#J#JKK 	w...GU+++ < 	.R---< 	(MM"h''' 466"" 	'MM$&+&&&466"" 	'MM$&+&&&&&	' 	'r   c                    g d}| j         d|v r|d         |v rt          j        d         }nt          j        d         }|                    d|           t	          |d         d          r|d         j        d	         d
k     r|                    dd           | j        \  }} |j        ||fi | dS d|d         i}d|v r|d         |d<   t          j        d         dz  |d<   |                    dd           | j        \  }}	}
d |
D             r't          ||
          D ]\  }} |j
        ||g|fi |  |j        ||	fi | dS )zDraw the data.)1234+rK   |_Nmarkerlines.linewidthzlines.markeredgewidth
linewidthsr^   r!   r      alphag?g      ?	linewidths2   c                     g | ]}||S r1   r   )r   rG   s     r   r   z2_RegressionPlotter.scatterplot.<locals>.<listcomp>  s    333rBNNNNr   )rP   r   rcParamsr   r   r!   rp   rT   r   zipr@   )r%   r?   r&   line_markerslwrK   rL   ci_kwsxsysr|   rG   s               r   r   z_RegressionPlotter.scatterplot  s    @??#33x=L#@#@\"34\"9:NN<,,,3w<11 ,S\5G5JQ5N5Nw+++$DAqBJq!##s##### s7|,F#~~"%g,w"%,/@"AD"HF;NN3###,KBC33S333 2 S\\ 2 2EArBGQFB11&1111BJr2%%%%%%%r   c                 d   |                      |          \  }}}|d         |d         f}|d         }|                    dt          j        d         dz            }|                    d|            |j        ||fi |\  }	| j        s||	j        j        dd<   | |j	        |g|R |d	d
 dS dS )zDraw the model.r   r   r^   r  r   g      ?r   Ng333333?)	facecolorr   )
r   popr   r  r   r@   r[   sticky_edgesrK   fill_between)
r%   r?   r&   r   r   r   edges
fill_colorr  lines
             r   r   z_RegressionPlotter.lineplot  s     !% 3 3B 7 7dIQb! \
WWT3<(9:S@AA{B''' d**c**} 	+%*D" BODN9NN
#NNNNNN ! r   )NNNrG   TTrH   rI   NNr   FFFFNNFTNNNN)NNN)rA   rB   rC   rD   rj   propertyrp   r   r   r   r   r   r   r   r   rc   ra   r@   r   r   r   r   r   rF   rF   F   sA        
 BFFJHMEIFJ#':6 :6 :6 :6x   X   !  ! X !D7 7 7)% )% )% )%V     &     "     >       *  = = ="' "' "'H &  &  &DO O O O Or   rF   	model_apiz    There are a number of mutually exclusive options for estimating the
    regression model. See the :ref:`tutorial <regression_tutorial>` for more
    information.    regplot_vs_lmplotz    The :func:`regplot` and :func:`lmplot` functions are closely related, but
    the former is an axes-level function while the latter is a figure-level
    function that combines :func:`regplot` and :class:`FacetGrid`.    rP   aJ      x_estimator : callable that maps vector -> scalar, optional
        Apply this function to each unique value of ``x`` and plot the
        resulting estimate. This is useful when ``x`` is a discrete variable.
        If ``x_ci`` is given, this estimate will be bootstrapped and a
        confidence interval will be drawn.    ri   a      x_bins : int or vector, optional
        Bin the ``x`` variable into discrete bins and then estimate the central
        tendency and a confidence interval. This binning only influences how
        the scatterplot is drawn; the regression is still fit to the original
        data.  This parameter is interpreted either as the number of
        evenly-sized (not necessary spaced) bins or the positions of the bin
        centers. When this parameter is used, it implies that the default of
        ``x_estimator`` is ``numpy.mean``.    rQ   aZ      x_ci : "ci", "sd", int in [0, 100] or None, optional
        Size of the confidence interval used when plotting a central tendency
        for discrete values of ``x``. If ``"ci"``, defer to the value of the
        ``ci`` parameter. If ``"sd"``, skip bootstrapping and show the
        standard deviation of the observations in each bin.    rT   z    scatter : bool, optional
        If ``True``, draw a scatterplot with the underlying observations (or
        the ``x_estimator`` values).    rU   z    fit_reg : bool, optional
        If ``True``, estimate and plot a regression model relating the ``x``
        and ``y`` variables.    rG   aw      ci : int in [0, 100] or None, optional
        Size of the confidence interval for the regression estimate. This will
        be drawn using translucent bands around the regression line. The
        confidence interval is estimated using a bootstrap; for large
        datasets, it may be advisable to avoid that computation by setting
        this parameter to None.    rR   z    n_boot : int, optional
        Number of bootstrap resamples used to estimate the ``ci``. The default
        value attempts to balance time and stability; you may want to increase
        this value for "final" versions of plots.    rM   a      units : variable name in ``data``, optional
        If the ``x`` and ``y`` observations are nested within sampling units,
        those can be specified here. This will be taken into account when
        computing the confidence intervals by performing a multilevel bootstrap
        that resamples both units and observations (within unit). This does not
        otherwise influence how the regression is estimated or drawn.    rS   z    seed : int, numpy.random.Generator, or numpy.random.RandomState, optional
        Seed or random number generator for reproducible bootstrapping.    rV   z    order : int, optional
        If ``order`` is greater than 1, use ``numpy.polyfit`` to estimate a
        polynomial regression.    rW   aw      logistic : bool, optional
        If ``True``, assume that ``y`` is a binary variable and use
        ``statsmodels`` to estimate a logistic regression model. Note that this
        is substantially more computationally intensive than linear regression,
        so you may wish to decrease the number of bootstrap resamples
        (``n_boot``) or set ``ci`` to None.    rX   z    lowess : bool, optional
        If ``True``, use ``statsmodels`` to estimate a nonparametric lowess
        model (locally weighted linear regression). Note that confidence
        intervals cannot currently be drawn for this kind of model.    rY   ai      robust : bool, optional
        If ``True``, use ``statsmodels`` to estimate a robust regression. This
        will de-weight outliers. Note that this is substantially more
        computationally intensive than standard linear regression, so you may
        wish to decrease the number of bootstrap resamples (``n_boot``) or set
        ``ci`` to None.    rZ   z    logx : bool, optional
        If ``True``, estimate a linear regression of the form y ~ log(x), but
        plot the scatterplot and regression model in the input space. Note that
        ``x`` must be positive for this to work.    
xy_partialz    {x,y}_partial : strings in ``data`` or matrices
        Confounding variables to regress out of the ``x`` or ``y`` variables
        before plotting.    r[   z    truncate : bool, optional
        If ``True``, the regression line is bounded by the data limits. If
        ``False``, it extends to the ``x`` axis limits.
    	xy_jitteraT      {x,y}_jitter : floats, optional
        Add uniform random noise of this size to either the ``x`` or ``y``
        variables. The noise is added to a copy of the data after fitting the
        regression, and only influences the look of the scatterplot. This can
        be helpful when plotting variables that take discrete values.    scatter_line_kwsz    {scatter,line}_kws : dictionaries
        Additional keyword arguments to pass to ``plt.scatter`` and
        ``plt.plot``.       orH   rI   )'rK   rL   huecolrowpalettecol_wrapheightaspectmarkerssharexsharey	hue_order	col_order	row_orderlegend
legend_outrP   ri   rQ   rT   rU   rG   rR   rM   rS   rV   rW   rX   rY   rZ   rN   rO   r[   r\   r]   r   r   	facet_kwsc       '         \  ' 'i ''fd}( |(d|            |(d|            |(d|           | t          d          ||||||| |!g})t          j        d |)D                                                       }*| |*         } t	          | f|||||||||	|d
'}+|+j        d},nt          |+j                  },t          |
t                    s|
g|,z  }
t          |
          |,k    rt          d	          d
|
i|+_
        d }-|+                    |-||           t          d"i d|d|d|d|d|d|d|d|d|d|d|d|d|d|d| d|!d|"d|#d|$d |%d!|&}. |+j        t          f||d|. |+                    ||           |r||||fvr|+                                 |+S )#Nc                 X    |  d}|!t          j        |t                     || <   d S d S )Nzj is deprecated from the `lmplot` function signature. Please update your code to pass it using `facet_kws`.)r   warnUserWarning)keyr)   msgr'  s      r   facet_kw_deprecationz$lmplot.<locals>.facet_kw_deprecationP  sJ     D D D 	 ?M#{+++ IcNNN ?r   r   r!  r&  z)Missing required keyword argument `data`.c                     g | ]}||S r1   r   )r   r   s     r   r   zlmplot.<locals>.<listcomp>b  s    <<<Aamammmr   )
r  r  r  r  r$  r#  r"  r  r  r  r   zSmarkers must be a singleton or a list of markers for each level of the hue variabler   c                     | ||g                                                              t                    }|                    |d           |                    d           d S )NF)updatey)scaley)to_numpyastypefloatupdate_datalimautoscale_view)r   rK   rL   r?   r&   xyss         r   r6  zlmplot.<locals>.update_datalim{  s_    Aq6l##%%,,U33
#u---
'''''r   )rK   rL   rP   ri   rQ   rT   rU   rG   rR   rM   rS   rV   rW   rX   rY   rZ   rN   rO   r[   r\   r]   r   r   r   )	TypeErrorr   rv   tolistr   	hue_namesre   r   r   r   hue_kwsmap_dataframedictr
   set_axis_labels
add_legend)/r   rK   rL   r  r  r  r  r  r  r  r  r   r!  r"  r#  r$  r%  r&  rP   ri   rQ   rT   rU   rG   rR   rM   rS   rV   rW   rX   rY   rZ   rN   rO   r[   r\   r]   r   r   r'  r.  	need_colscolsfacets	n_markersr6  regplot_kwss/                                          `       r   r	   r	   @  s    	! ! ! ! ! 6***6***z222|CDDD AsCeY	BI9<<<<<==DDFFD:D 3CyIfx	 
  F 		())	gt$$ ()i'
7||y   > ? ? 	?(FN( ( (
 1222    K(.59T!(-/R8>FKe T  *2 ;A& v	 !D	 -6I	 BK	
 
 %-H
 8@x  K +3(K F:A::k:::
1a     3?S#J)>)>Mr   aa
      Plot data and regression model fits across a FacetGrid.

    This function combines :func:`regplot` and :class:`FacetGrid`. It is
    intended as a convenient interface to fit regression models across
    conditional subsets of a dataset.

    When thinking about how to assign variables to different facets, a general
    rule is that it makes sense to use ``hue`` for the most important
    comparison, followed by ``col`` and ``row``. However, always think about
    your particular dataset and the goals of the visualization you are
    creating.

    {model_api}

    The parameters to this function span most of the options in
    :class:`FacetGrid`, although there may be occasional cases where you will
    want to use that class and :func:`regplot` directly.

    Parameters
    ----------
    {data}
    x, y : strings, optional
        Input variables; these should be column names in ``data``.
    hue, col, row : strings
        Variables that define subsets of the data, which will be drawn on
        separate facets in the grid. See the ``*_order`` parameters to control
        the order of levels of this variable.
    {palette}
    {col_wrap}
    {height}
    {aspect}
    markers : matplotlib marker code or list of marker codes, optional
        Markers for the scatterplot. If a list, each marker in the list will be
        used for each level of the ``hue`` variable.
    {share_xy}

        .. deprecated:: 0.12.0
            Pass using the `facet_kws` dictionary.

    {{hue,col,row}}_order : lists, optional
        Order for the levels of the faceting variables. By default, this will
        be the order that the levels appear in ``data`` or, if the variables
        are pandas categoricals, the category order.
    legend : bool, optional
        If ``True`` and there is a ``hue`` variable, add a legend.
    {legend_out}

        .. deprecated:: 0.12.0
            Pass using the `facet_kws` dictionary.

    {x_estimator}
    {x_bins}
    {x_ci}
    {scatter}
    {fit_reg}
    {ci}
    {n_boot}
    {units}
    {seed}
    {order}
    {logistic}
    {lowess}
    {robust}
    {logx}
    {xy_partial}
    {truncate}
    {xy_jitter}
    {scatter_line_kws}
    facet_kws : dict
        Dictionary of keyword arguments for :class:`FacetGrid`.

    See Also
    --------
    regplot : Plot data and a conditional model fit.
    FacetGrid : Subplot grid for plotting conditional relationships.
    pairplot : Combine :func:`regplot` and :class:`PairGrid` (when used with
               ``kind="reg"``).

    Notes
    -----

    {regplot_vs_lmplot}

    Examples
    --------

    .. include:: ../docstrings/lmplot.rst

    )rK   rL   rP   ri   rQ   rT   rU   rG   rR   rM   rS   rV   rW   rX   rY   rZ   rN   rO   r[   r<   r\   r]   r_   r^   r   r   r   r?   c                   t          ||| |||||||	|
||||||||||||||          }|t          j                    }|i nt          j        |          }||d<   |i nt          j        |          }|                    |||           |S )Nr   )rF   pltgcacopyr@   )r   rK   rL   rP   ri   rQ   rT   rU   rG   rR   rM   rS   rV   rW   rX   rY   rZ   rN   rO   r[   r<   r\   r]   r_   r^   r   r   r   r?   plotters                                 r   r
   r
     s     !At[&$!('2vud!&&&$!*Ix!)8UE	C CG 
zWYY#+"";1G1GK"K%rr49X+>+>HLL[(+++Ir   a      Plot data and a linear regression model fit.

    {model_api}

    Parameters
    ----------
    x, y: string, series, or vector array
        Input variables. If strings, these should correspond with column names
        in ``data``. When pandas objects are used, axes will be labeled with
        the series name.
    {data}
    {x_estimator}
    {x_bins}
    {x_ci}
    {scatter}
    {fit_reg}
    {ci}
    {n_boot}
    {units}
    {seed}
    {order}
    {logistic}
    {lowess}
    {robust}
    {logx}
    {xy_partial}
    {truncate}
    {xy_jitter}
    label : string
        Label to apply to either the scatterplot or regression line (if
        ``scatter`` is ``False``) for use in a legend.
    color : matplotlib color
        Color to apply to all plot elements; will be superseded by colors
        passed in ``scatter_kws`` or ``line_kws``.
    marker : matplotlib marker code
        Marker to use for the scatterplot glyphs.
    {scatter_line_kws}
    ax : matplotlib Axes, optional
        Axes object to draw the plot onto, otherwise uses the current Axes.

    Returns
    -------
    ax : matplotlib Axes
        The Axes object containing the plot.

    See Also
    --------
    lmplot : Combine :func:`regplot` and :class:`FacetGrid` to plot multiple
             linear relationships in a dataset.
    jointplot : Combine :func:`regplot` and :class:`JointGrid` (when used with
                ``kind="reg"``).
    pairplot : Combine :func:`regplot` and :class:`PairGrid` (when used with
               ``kind="reg"``).
    residplot : Plot the residuals of a linear regression model.

    Notes
    -----

    {regplot_vs_lmplot}


    It's also easy to combine :func:`regplot` and :class:`JointGrid` or
    :class:`PairGrid` through the :func:`jointplot` and :func:`pairplot`
    functions, although these do not directly accept all of :func:`regplot`'s
    parameters.

    Examples
    --------

    .. include:: ../docstrings/regplot.rst

    )rK   rL   rN   rO   rX   rV   rY   r<   r_   r^   r   r   r?   c                   t          ||| d||||||
|	          }|t          j                    }|                    |j                  \  }}}|j        |z
  |_        |rd|_        nd|_        |                    ddd	           |i n|	                                }|i n|	                                }|
                    |||           |S )
a  Plot the residuals of a linear regression.

    This function will regress y on x (possibly as a robust or polynomial
    regression) and then draw a scatterplot of the residuals. You can
    optionally fit a lowess smoother to the residual plot, which can
    help in determining if there is structure to the residuals.

    Parameters
    ----------
    data : DataFrame, optional
        DataFrame to use if `x` and `y` are column names.
    x : vector or string
        Data or column name in `data` for the predictor variable.
    y : vector or string
        Data or column name in `data` for the response variable.
    {x, y}_partial : vectors or string(s) , optional
        These variables are treated as confounding and are removed from
        the `x` or `y` variables before plotting.
    lowess : boolean, optional
        Fit a lowess smoother to the residual scatterplot.
    order : int, optional
        Order of the polynomial to fit when calculating the residuals.
    robust : boolean, optional
        Fit a robust linear regression when calculating the residuals.
    dropna : boolean, optional
        If True, ignore observations with missing data when fitting and
        plotting.
    label : string, optional
        Label that will be used in any plot legends.
    color : matplotlib color, optional
        Color to use for all elements of the plot.
    {scatter, line}_kws : dictionaries, optional
        Additional keyword arguments passed to scatter() and plot() for drawing
        the components of the plot.
    ax : matplotlib axis, optional
        Plot into this axis, otherwise grab the current axis or make a new
        one if not existing.

    Returns
    -------
    ax: matplotlib axes
        Axes with the regression plot.

    See Also
    --------
    regplot : Plot a simple linear regression model.
    jointplot : Draw a :func:`residplot` with univariate marginal distributions
                (when used with ``kind="resid"``).

    Examples
    --------

    .. include:: ../docstrings/residplot.rst

    N)rG   rV   rY   rN   rO   r<   r^   r_   )r   TFr   :z.2)lsc)rF   rG  rH  r   rK   rL   rX   rU   axhlinerI  r@   )r   rK   rL   rN   rO   rX   rV   rY   r<   r_   r^   r   r   r?   rJ  r   r   s                    r   r   r   V  s    z !At',V+4	(.e5J J JG
 
zWYY ''WY'77JAtQ	D GI    JJqSDJ!!! $+""1A1A1C1CK%rr8==??HLL[(+++Ir   r   r1   )"rD   rI  textwrapr   r   numpyr   pandasr3   
matplotlibr   matplotlib.pyplotpyplotrG  statsmodelsr   ImportError r   r   ry   axisgridr   r   __all__r   rF   r>  _regression_docsupdater	   r   r
   r   r   r   r   <module>r]     s    ? ?                                                , , , , , , , , -
,
,*" *" *" *" *" *" *" *"ZtO tO tO tO tO tO tO tOn 4   f  	 	 	 f  	 	 	   	 	 	& 6 	 		 		 		': 
  
	 
	 
	;H F  	 	 	IR F  	 	 	S\ v  	 	 	]l 6  	 	 	mx &  	 	 	yH 
  
	 
	 
	IP &  	 	 	QZ V  	 	 	[j 6  	 	 	kv 6  	 	 	wF 
  
	 
	 
	GR v  	 	 	S\ V  	 	 	]f f  	 	 	gt V  	 	 	u @    $ $ $
 d$D4!SDd4	tTb
TU5uD4TTQ Q Q Q QhY Y Y	 Y	r 
sY$ Y$r #sY$ Y$z 
DT$2d$	QuU	$$$
d3t    6H&& H H	 H	P 
QH$ H$P #QH$ H$X 
VDd5
E$d$t	V V V V V V Vs   
/ 99