
    'YHh                     .    d dl mZ d dlZddZ	 	 	 ddZy)    Nc                    t        j                         }|t        |       n|}| }|d| }|j                  d      }|j	                  t        j                  |      |d| d       |j                  d       t        j                  |j                               }|d   |d   z
  }|dt        j                  | |g      z  z  }|j                  t        j                  |             |j                  |       t        j                  |j                               }	d}
|	d   |	d   z
  }|	|
t        j                  | |g      z  z  }	|j                  |	       |j                  d	       |j                  d
       |j!                  |       ||z  }t        j"                  |      }|j                  d      }|j	                  t        j                  |      |d| d       |j	                  t        j                  |      |d| d       |j                  d       t        j                  |j                               }|d   |d   z
  }|dt        j                  | |g      z  z  }|j                  t        j                  |             |j                  |       t        j                  |j                               }	d}
|	d   |	d   z
  }|	|
t        j                  | |g      z  z  }	|j                  |	       |j                  d       |j                  d       |j!                  |       |j%                  ddgd       |j'                          |S )a
  
    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 : str
        label of x-axis

    Returns
    -------
    Figure
        Handle to the figure.
    Ny   zb-oT)tight   r   g{Gz?z
Scree Plot
Eigenvaluez   zg--ozVariance Explained
Proportion
Cumulative   )loc)pltfigurelenadd_subplotplotnparange	autoscalearrayget_xlim
set_xticksset_xlimget_ylimset_ylim	set_title
set_ylabel
set_xlabelcumsumlegendtight_layout)	eigenvals	total_varncompx_labelfigvalsaxxlimspylimscaleper_variancecumper_variances                W/var/www/html/planif/env/lib/python3.12/site-packages/statsmodels/multivariate/plots.py
plot_screer/      s   * **,C#mC	NED<D 
	BGGBIIed7UmU3LLtL88BKKM"D	a47	BD288bS"I&&&DMM"))E"#KK88BKKM"DE	a47	BEBHHrc2Y'''DKKLLMM,MM')#Lii-O		BGGBIIel7U3U;GGBIIeog6?LLtL88BKKM"D	a47	BD288bS"I&&&DMM"))E"#KK88BKKM"DE	a47	BEBHHrc2Y'''DKKLL%&MM,MM'II|\*I2J    c                    | j                   \  }}|9g }t        |      D ])  }t        |dz   |      D ]  }	|j                  ||	g        + |t        |      D cg c]  }d|z  	 }}|t        |      D cg c]  }d|z  	 }}g }
|D ]  }|d   }|d   }	t        j                  d      }|
j                  |       |j                  d      }t        | j                   d         D ](  }t        j                  | ||f   | ||	f   ||   d	
       * |j                  | dd|f   | dd|	f   d       |j                  |       |A||    d||   dd}||	    d||	   dd}|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!                           |
S c c}w c c}w )a  
    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
    Nr   z	factor %dzvar %dr   )   r2   )figsizeo      )fontsizeboz (z.1fz%)g?zk--equaldatalim)shaperangeappendr   r   r   textr   r   r   r   r   r   
set_aspectr   r   r    )loadings	col_names	row_namesloading_pairspercent_variancetitlek_varn_factorijfigsitemr%   r'   kx_stry_strvr(   r*   s                       r.   plot_loadingsrO   L   st   2 nnOE8x 	-A1q5* -$$aV,-	- .3Ho>[1_>	>+0<8aX\8	8D GGjj(C__S!x~~a() 	0AHHXad^Xad^q\B0	0 	AA5
U' |nB'7':3&?rBE |nB'7':3&?rBEMM% MM% MM)A,'MM)A,'xx!Q xx!Q 
q!fe$
Ae$
gy)
D
D78 KA ?8s   I7I)Nfactor)NNNNzFactor patterns)matplotlib.pyplotpyplotr   numpyr   r/   rO    r0   r.   <module>rU      s#     DN 7;7;)@r0   