
    M/Ph                     F    d Z ddlZddlmZ ddlmZ dgZddZ	 	 	 ddZ	dS )a  create scatterplot with confidence ellipsis

Author: Josef Perktold
License: BSD-3

TODO: update script to use sharex, sharey, and visible=False
    see https://www.scipy.org/Cookbook/Matplotlib/Multiple_Subplots_with_One_Axis_Label
    for sharex I need to have the ax of the last_row when editing the earlier
    rows. Or you axes_grid1, imagegrid
    http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/overview.html
    N)stats   )utilsscatter_ellipseffffff?c           	      f   ddl m} t          j                            |          \  }}|d         t          j                            |d                   z  }t          j        |d         |d         z            }	d|	z  t          j        z  }	dt          j        |t          j
                            |d          z            z  } || dd         |d         |d         d|	z   d|d	          }
|
                    |j                   |
                    d
           |                    |
           dS )z%Support function for scatter_ellipse.r   )Ellipser         Nnoneg      ?)angle	facecolor	edgecolorlw      ?)matplotlib.patchesr	   nplinalgeighnormarctanpisqrtr   chi2ppfset_clip_boxbbox	set_alpha
add_artist)meancovaxlevelcolorr	   vwur   ells              _/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/statsmodels/graphics/plot_grids.py_make_ellipser*      s   ******9>>#DAq	!ry~~ad###AIad1Q4i  E%K"%E	BGA
ua000111A
'$rr(AaD!A$cEkV!  C RWMM#MM#    ?Fc           
      	   t          j        |          }ddlm} t	          j        |           } | j        d         }	|d t          |	          D             }t          dddd	          }
|r|
	                    |           t          d
          }|r|	                    |           | 
                    d          }t	          j        | d          }t          d|	          D ]L}d}t          |          D ]6}|                    |	dz
  |	dz
  |dz
  |	dz
  z  |z   dz             }|                    d          }|j                            |           |j                            |           t	          j        ||g          } |j        | dd|f         j        i |
 t	          j        |          r|g}|D ]+}t+          ||         ||dddf         |f         |fd|i| ,|r&|                    ||          d||                     |                                                                sF|s|                    g            nI|j                            |                    d                     n|                    ||                    |                                                                r|                    ||                    nE|s|                    g            n-|j                            |                    d                     t	          j         | d          }||dddf         |f         }|!                                }|"                                }|d         d|d         |d         z
  z  z   }|d         dk     s|d         dk     r0||         d         |k    r|d         d|d         |d         z
  z  z   }n|d         d|d         |d         z
  z  z
  }|d         d|d         |d         z
  z  z   }|#                    ||d|d         z             8N|j$        D ]}|                                                                r-|j                            |                    d                     |                                                                r-|j                            |                    d                     |S )a  Create a grid of scatter plots with confidence ellipses.

    ell_kwds, plot_kdes not used yet

    looks ok with 5 or 6 variables, too crowded with 8, too empty with 1

    Parameters
    ----------
    data : array_like
        Input data.
    level : scalar, optional
        Default is 0.9.
    varnames : list[str], optional
        Variable names.  Used for y-axis labels, and if `add_titles` is True
        also for titles.  If not given, integers 1..data.shape[1] are used.
    ell_kwds : dict, optional
        UNUSED
    plot_kwds : dict, optional
        UNUSED
    add_titles : bool, optional
        Whether or not to add titles to each subplot.  Default is False.
        Titles are constructed from `varnames`.
    keep_ticks : bool, optional
        If False (default), remove all axis ticks.
    fig : Figure, optional
        If given, this figure is simply returned.  Otherwise a new figure is
        created.

    Returns
    -------
    Figure
        If `fig` is None, the created figure.  Otherwise `fig` itself.

    Examples
    --------
    >>> import statsmodels.api as sm
    >>> import matplotlib.pyplot as plt
    >>> import numpy as np

    >>> from statsmodels.graphics.plot_grids import scatter_ellipse
    >>> data = sm.datasets.statecrime.load_pandas().data
    >>> fig = plt.figure(figsize=(8,8))
    >>> scatter_ellipse(data, varnames=data.columns, fig=fig)
    >>> plt.show()

    .. plot:: plots/graphics_plot_grids_scatter_ellipse.py
    r   Nr   c                     g | ]}d |z  S )zvar%d ).0is     r)   
<listcomp>z#scatter_ellipse.<locals>.<listcomp>a   s    666AGaK666r+   r   .kr   )lsmarkerr$   alpha)r$   )rowvarz% 3.1fr#   -   g?)r   r   g      пg      ?g?g?z$\rho=%0.2f$)%r   create_mpl_figmatplotlib.tickertickerr   
asanyarrayshaperangedictupdater    r!   add_subplotFormatStrFormatteryaxisset_major_formatterxaxisarrayplotTisscalarr*   	set_titleget_subplotspecis_first_col
set_yticksset_major_locatorMaxNLocator
set_ylabelis_last_row
set_xlabel
set_xtickscorrcoefget_xlimget_ylimtextaxes)datar#   varnamesell_kwds	plot_kwds
add_titles
keep_ticksfigmtickernvars
plot_kwds_	ell_kwds_dmeandcovr1   ax_lastjr"   	formatteridxr7   dcorrdcxlimylimyrangeqytxts                               r)   r   r   (   s   d 
s
#
#C''''''=DJqME66u6663cBBBJ %)$$$#I #"""IIaLLE6$q!!!D1e__ ;6 ;6q 8	6 8	6Aq%'AaC%'?13DQ3FGGB  228<<IH((333H((333(Aa5//CBGT!!!C%[]1j111{5!!   & &eCj$s111T6{C/?*@" & &E &$& & & &  =;;hqk;;<<<%%''4466 +! GMM"%%%%H..w/B/B1/E/EFFFFhqk***!!##//11 Ghqk****! GMM"%%%%H..w/B/B1/E/EFFFKQ///Es111T6{C'(B;;==D;;==D 1gtAwa'8 99G#w2c7T>>eCjmg6M6M!Wsd1gQ&788!Wsd1gQ&788a3$q'DG"344BGGBORW45555q8	6t h ? ?++-- 	?H&&w':':1'='=>>>,,.. 	?H&&w':':1'='=>>>Jr+   )r   N)r,   NNNFFN)
__doc__numpyr   scipyr    r   __all__r*   r   r/   r+   r)   <module>rx      s   
 
                
   $ >BAFI I I I I Ir+   