
    'YHh                     D    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	y)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_ellipsec           	      .   ddl m} t        j                  j	                  |      \  }}|d   t        j                  j                  |d         z  }t        j                  |d   |d   z        }	d|	z  t        j                  z  }	dt        j                  |t        j                  j                  |d      z        z  } || dd |d   |d   d|	z   d|d	      }
|
j                  |j                         |
j                  d
       |j                  |
       y)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              X/var/www/html/planif/env/lib/python3.12/site-packages/statsmodels/graphics/plot_grids.py_make_ellipser)      s    *99>>#DAq	!ryy~~ad##AIIad1Q4i E%K"%%E	BGGA

ua0011A
$r(AaD!A$cEkV!C RWWMM#MM#    c           
         t        j                  |      }ddlm} t	        j
                  |       } | j                  d   }	|t        |	      D 
cg c]  }
d|
z  	 }}
t        dddd	      }|r|j                  |       t        d
      }|r|j                  |       | j                  d      }t	        j                  | d      }t        d|	      D ]  }
d}t        |
      D ]  }|j                  |	dz
  |	dz
  |
dz
  |	dz
  z  |z   dz         }|j                  d      }|j                  j                  |       |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|j-                  ||
    d||           |j/                         j1                         s?|s|j3                  g        n?|j                  j5                  |j7                  d             n|j9                  ||
          |j/                         j;                         r|j=                  ||          n>|s|j?                  g        n*|j                   j5                  |j7                  d             t	        j@                  | d      }||dddf   |f   }|jC                         }|jE                         }|d   d|d   |d   z
  z  z   }|d   dk  s|d   dk  r ||   d   |kD  r|d   d|d   |d   z
  z  z   }n|d   d|d   |d   z
  z  z
  }|d   d|d   |d   z
  z  z   }|jG                  ||d|d   z           |jH                  D ]  }|j/                         j;                         r*|j                   j5                  |j7                  d             |j/                         j1                         sj|j                  j5                  |j7                  d              |S c c}
w )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   zvar%dr   .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i
plot_kwds_	ell_kwds_dmeandcovax_lastjr!   	formatteridxr0   dcorrdcxlimylimyrangeqytxts                               r(   r   r   (   s   d 

s
#C'==DJJqME).u6AGaK663cBJ)$#I"IIaLE66$q!D1e_ ;6q 8	6Aq%'AaC%'?13DQ3FGB  228<IHH((3HH((3((Aa5/CBGGT!C%[]]1j1{{5! &eCj$s1T6{C/?*@" &E &$&& }Ahqk];<%%'446!MM"%HH..w/B/B1/EFhqk*!!#//1hqk*!MM"%HH..w/B/B1/EFKKQ/Es1T6{C'(B;;=D;;=D 1gtAwa'8 99G#w2c7T>eCjmg6M!Wsd1gQ&788!Wsd1gQ&788a3$q'DG"344BGGBORW45q8	6;6z hh ?++-HH&&w':':1'=>,,.HH&&w':':1'=>	? Ja 7s   Q)gffffff?N)g?NNNFFN)
__doc__numpyr   scipyr    r   __all__r)   r    r*   r(   <module>rs      s4   
   
$ >BAFIr*   