U
    ÃmœdÀ  ã                   @   sP   d Z ddlmZ ddgZdd„ Zddd„Zdd	d„Zd
d„ Zdd„ Zdd„ Z	dS )z.Helper functions for graphics with Matplotlib.é    )ÚlrangeÚcreate_mpl_axÚcreate_mpl_figc                  C   s*   zddl m}  W n   tdƒ‚Y nX | S )z6This function is not needed outside this utils module.r   NzMatplotlib is not found.)Zmatplotlib.pyplotZpyplotÚImportError)Úplt© r   úS/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/statsmodels/graphics/utils.pyÚ_import_mpl   s
    r	   Nc                 C   s0   | dkr"t ƒ }| ¡ }| d¡} n| j}|| fS )aÉ  Helper function for when a single plot axis is needed.

    Parameters
    ----------
    ax : AxesSubplot, optional
        If given, this subplot is used to plot in instead of a new figure being
        created.

    Returns
    -------
    fig : Figure
        If `ax` is None, the created figure.  Otherwise the figure to which
        `ax` is connected.
    ax : AxesSubplot
        The created axis if `ax` is None, otherwise the axis that was passed
        in.

    Notes
    -----
    This function imports `matplotlib.pyplot`, which should only be done to
    create (a) figure(s) with ``plt.figure``.  All other functionality exposed
    by the pyplot module can and should be imported directly from its
    Matplotlib module.

    See Also
    --------
    create_mpl_fig

    Examples
    --------
    A plotting function has a keyword ``ax=None``.  Then calls:

    >>> from statsmodels.graphics import utils
    >>> fig, ax = utils.create_mpl_ax(ax)
    Néo   )r	   ÚfigureZadd_subplot)Úaxr   Úfigr   r   r   r      s    $c                 C   s   | dkrt ƒ }|j|d�} | S )aè  Helper function for when multiple plot axes are needed.

    Those axes should be created in the functions they are used in, with
    ``fig.add_subplot()``.

    Parameters
    ----------
    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 the input `fig` is
        returned.

    See Also
    --------
    create_mpl_ax
    N)Úfigsize)r	   r   )r   r   r   r   r   r   r   ?   s    c                 C   sŽ   | dkrt |jjd ƒ} t| tƒr2|j|  }| }nTt| ttfƒrvg }g }| D ]&}t||ƒ\}}| 	|¡ | 	|¡ qLn| }|j 
| ¡}||fS )zr
    Give a name or an integer and return the name and integer location of the
    column in a design matrix.
    Né   )r   ZexogÚshapeÚ
isinstanceÚintZ
exog_namesÚtupleÚlistÚmaybe_name_or_idxÚappendÚindex)ÚidxÚmodelZ	exog_nameZexog_idxÚitemZexog_name_itemZexog_idx_itemr   r   r   r   \   s    


r   c                 C   sx   t | ddƒ}|st | ddƒ}|slt | ddgƒ}t|ƒdkr>dn| jd }dd„ t|ƒD ƒ}|dkrt|d }n| ¡ }|S )	z•
    Input can be an array or pandas-like. Will handle 1d array-like but not
    2d. Returns a str for 1d data or a list of strings for 2d data.
    ÚnameNÚcolumnsr   r   c                 S   s   g | ]}d ‘qS )zX%dr   )Ú.0Ú_r   r   r   Ú
<listcomp>€   s     z"get_data_names.<locals>.<listcomp>r   )ÚgetattrÚlenr   ÚrangeÚtolist)Zseries_or_dataframeÚnamesr   Znvarsr   r   r   Úget_data_namesu   s    
r%   c                 K   sB   | D ]8}|| }|| }	|| }
|j ||	f|
d|dœ|—Ž q|S )z\
    Annotate Axes with labels, points, offset_points according to the
    given index.
    zoffset points)ZxytextZ
textcoordsÚsize)Zannotate)r   ÚlabelsZpointsZoffset_pointsr&   r   ÚkwargsÚiÚlabelÚpointÚoffsetr   r   r   Úannotate_axesˆ   s    ÿÿr-   )N)NN)
Ú__doc__Zstatsmodels.compat.pythonr   Ú__all__r	   r   r   r   r%   r-   r   r   r   r   Ú<module>   s   

.
