ó
áp7]c           @   sF   d  d l  j Z d  d l Z d d d „ Z d d d d d d „ Z d S(   iÿÿÿÿNt   factorc         C   sæ  t  j ƒ  } | d k r$ t |  ƒ n | } |  } | |  } | j d ƒ } | j t j | ƒ | |  d ƒ | j d t	 ƒ t j
 | j ƒ  ƒ } | d | d } | d t j
 | | g ƒ 7} | j t j | ƒ ƒ | j | ƒ t j
 | j ƒ  ƒ }	 d }
 |	 d |	 d } |	 |
 t j
 | | g ƒ 7}	 | j |	 ƒ | j d ƒ | j d ƒ | j | ƒ | | } t j | ƒ } | j d	 ƒ } | j t j | ƒ | |  d ƒ | j t j | ƒ | |  d
 ƒ | j d t	 ƒ t j
 | j ƒ  ƒ } | d | d } | d t j
 | | g ƒ 7} | j t j | ƒ ƒ | j | ƒ t j
 | j ƒ  ƒ }	 d }
 |	 d |	 d } |	 |
 t j
 | | g ƒ 7}	 | j |	 ƒ | j d ƒ | j d ƒ | j | ƒ | j d d g d d ƒ| j ƒ  | S(   s  
    Plot of the ordered eigenvalues and variance explained for the loadings

    Parameters
    ----------
    eigenvals : array-like
        THe eigenvalues
    total_var : float
        the total variance (for plotting percent variance explained)
    ncomp : int, optional
        Number of factors to include in the plot.  If None, will
        included the same as the number of maximum possible loadings
    x_label : string
        label of x-axis

    Returns
    -------
    fig : figure
        Handle to the figure
    iy   s   b-ot   tighti   i    g{®Gáz”?s
   Scree Plott
   Eigenvalueiz   s   g--os   Variance Explainedt
   Proportiont
   Cumulativet   loci   N(   t   pltt   figuret   Nonet   lent   add_subplott   plott   npt   aranget	   autoscalet   Truet   arrayt   get_xlimt
   set_xtickst   set_xlimt   get_ylimt   set_ylimt	   set_titlet
   set_ylabelt
   set_xlabelt   cumsumt   legendt   tight_layout(   t	   eigenvalst	   total_vart   ncompt   x_labelt   figt   valst   axt   xlimt   spt   ylimt   scalet   per_variancet   cumper_variance(    (    s=   lib/python2.7/site-packages/statsmodels/multivariate/plots.pyt
   plot_scree   sT    
 
  
s   Factor patternsc         C   sÏ  |  j  \ } } | d
 k rl g  } xH t | ƒ D]7 } x. t | d | ƒ D] }	 | j | |	 g ƒ qH Wq. Wn  | d
 k rž g  t | ƒ D] } d | ^ q… } n  | d
 k rÐ g  t | ƒ D] } d | ^ q· } n  g  }
 xò| D]ê} | d } | d }	 t j d d ƒ } |
 j | ƒ | j d ƒ } xL t |  j  d ƒ D]7 } t j |  | | f |  | |	 f | | d d	 ƒq9W| j |  d
 d
 … | f |  d
 d
 … |	 f d ƒ | j	 | ƒ | d
 k	 rd | | | | f } d | |	 | |	 f } | j
 | ƒ | j | ƒ n" | j
 | | ƒ | j | |	 ƒ d } t j | | g ƒ } t j | | g ƒ } | j | d d g d ƒ | j d d g | d ƒ | j d d ƒ | j | ƒ | j | ƒ | j ƒ  qÝ W|
 S(   s­  
    Plot factor loadings in 2-d plots

    Parameters
    ----------
    loadings : array like
        Each column is a component (or factor)
    col_names : a list of strings
        column names of `loadings`
    row_names : a list of strings
        row names of `loadings`
    loading_pairs : None or a list of tuples
        Specify plots. Each tuple (i, j) represent one figure, i and j is
        the loading number for x-axis and y-axis, respectively. If `None`,
        all combinations of the loadings will be plotted.
    percent_variance : array-like
        The percent variance explained by each factor.

    Returns
    -------
    figs : a list of figure handles

    i   s	   factor %ds   var %di    t   figsizei   io   t   fontsizei   Nt   bos   %s (%.1f%%)gÍÌÌÌÌÌð?s   k--t   equalt   datalim(   i   i   (   t   shapeR   t   ranget   appendR   R   R
   t   textR   R   R   R   R   R   t
   set_aspectR   R   R   (   t   loadingst	   col_namest	   row_namest   loading_pairst   percent_variancet   titlet   k_vart   n_factort   it   jt   figst   itemR    R"   t   kt   x_strt   y_strt   vR#   R%   (    (    s=   lib/python2.7/site-packages/statsmodels/multivariate/plots.pyt   plot_loadingsL   sN    &&

 3(   t   matplotlib.pyplott   pyplotR   t   numpyR   R   R)   RD   (    (    (    s=   lib/python2.7/site-packages/statsmodels/multivariate/plots.pyt   <module>   s
   G