ó
áp7]c           @   s|   d  Z  d d l m Z d d l Z d d l m Z d d l m Z d g Z	 d d d	  Z d
 d d d e e d d  Z d S(   sŽ  create scatterplot with confidence ellipsis

Author: Josef Perktold
License: BSD-3

TODO: update script to use sharex, sharey, and visible=False
    see http://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
i˙˙˙˙(   t   rangeN(   t   statsi   (   t   utilst   scatter_ellipsegffffffî?c         C   sý   d d l  m } t j j |  \ } } | d t j j | d  } t j | d | d  }	 d |	 t j }	 d t j | t	 j
 j | d   } | |  d  | d | d d |	 d d d	 | d
 d }
 |
 j | j  |
 j d  | j |
  d S(   s%   Support function for scatter_ellipse.i˙˙˙˙(   t   Ellipsei    i   i´   i   t	   facecolort   nonet	   edgecolort   lwg      ř?g      ŕ?N(   t   matplotlib.patchesR   t   npt   linalgt   eight   normt   arctant   pit   sqrtR   t   chi2t   ppft   set_clip_boxt   bboxt	   set_alphat
   add_artist(   t   meant   covt   axt   levelt   colorR   t   vt   wt   ut   anglet   ell(    (    s>   lib/python2.7/site-packages/statsmodels/graphics/plot_grids.pyt   _make_ellipse   s    &(	gÍĚĚĚĚĚě?c      
   C   sc  t  j |  } d d l j } t j |   }  |  j d }	 | d k rl g  t |	  D] }
 d |
 ^ qS } n  t	 d d d d d	 d
 d d  } | rŁ | j
 |  n  t	 d	 d
  } | rČ | j
 |  n  |  j d  } t j |  d d } xt d |	  D]ű}
 d } xět |
  D]Ţ} | j |	 d |	 d |
 d |	 d | d  } | j d  } | j j |  | j j |  t j | |
 g  } | j |  d d  | f j |   t j |  rÎ| g } n  xE | D]= } t | | | | d d  d f | f | d | | qŐW| r>| j d | |
 | | f  n  | j   s|| s`| j g   q| j j | j d   n | j | |
  | j   r­| j | |  n/ | sĂ| j g   n | j j | j d   t j  |  d d } | | d d  d f | f } | j!   } | j"   } | d d | d | d } | d d k  s{| d d k  r| | d | k r| d d | d | d } n | d d | d | d } | d d | d | d } | j# | | d | d  qWqü Wxa | j$ D]V } | j   r3| j j | j d   n  | j   r| j j | j d   qqW| S(   sř  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 of 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 : Matplotlib figure instance, optional
        If given, this figure is simply returned.  Otherwise a new figure is
        created.

    Returns
    -------
    fig : Matplotlib figure instance
        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_correlation_plot_corr_grid.py
    i˙˙˙˙Ni   s   var%dt   lsR   t   markert   .R   t   kt   alphag      ŕ?i    t   rowvars   % 3.1fR   s   %s-%si   gŮ?g      Đżg      Đ?gš?gÉ?s   $\rho=%0.2f$(   i   i    (   i   i    (   i   i    (%   R   t   create_mpl_figt   matplotlib.tickert   tickerR
   t
   asanyarrayt   shapet   NoneR    t   dictt   updateR   R   t   add_subplott   FormatStrFormattert   yaxist   set_major_formattert   xaxist   arrayt   plott   Tt   isscalarR!   t	   set_titlet   is_first_colt
   set_ytickst   set_major_locatort   MaxNLocatort
   set_ylabelt   is_last_rowt
   set_xlabelt
   set_xtickst   corrcoeft   get_xlimt   get_ylimt   textt   axes(   t   dataR   t   varnamest   ell_kwdst	   plot_kwdst
   add_titlest
   keep_tickst   figt   mtickert   nvarst   it
   plot_kwds_t	   ell_kwds_t   dmeant   dcovt   ax_lastt   jR   t	   formattert   idxR&   t   dcorrt   dct   xlimt   ylimt   yrangeqt   ytt   xt(    (    s>   lib/python2.7/site-packages/statsmodels/graphics/plot_grids.pyR   *   sp    2&!1#0" 4!# (   t   __doc__t   statsmodels.compat.pythonR    t   numpyR
   t   scipyR   t    R   t   __all__R-   R!   t   FalseR   (    (    (    s>   lib/python2.7/site-packages/statsmodels/graphics/plot_grids.pyt   <module>   s   			