
    M/Ph                     F    d Z ddlmZ ddgZd ZddZddZd	 Zd
 Zd Z	dS )z.Helper functions for graphics with Matplotlib.    )lrangecreate_mpl_axcreate_mpl_figc                  >    	 ddl m}  n#  t          d          xY w| S )z6This function is not needed outside this utils module.r   NzMatplotlib is not found.)matplotlib.pyplotpyplotImportError)plts    Z/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/statsmodels/graphics/utils.py_import_mplr      s9    6'''''''64555Js   	 Nc                     | 8t                      }|                                }|                    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)
    No   )r   figureadd_subplot)axr
   figs      r   r   r      sC    H 
zmmjjll__S!!i7N    c                 R    | $t                      }|                    |          } | 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
   s      r   r   r   ?   s*    , {mmjjj))Jr   c                    | t          |j        j        d                   } t          | t                    r|j        |          }| }nt          | t          t          f          rGg }g }| D ]?}t          ||          \  }}|	                    |           |	                    |           @n| }|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   exogshape
isinstanceint
exog_namestuplelistmaybe_name_or_idxappendindex)idxmodel	exog_nameexog_idxitemexog_name_itemexog_idx_items          r   r   r   \   s    
 {UZ%a())#s /$S)		C%	'	' 	/	 	+ 	+D,=dE,J,J)NM^,,,OOM****	+
 	#))#..hr   c                 2   t          | dd          }|st          | dd          }|s\t          | ddg          }t          |          dk    rdn| j        d         }d t          |          D             }|dk    r|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                     g | ]}d S )zX%d ).0_s     r   
<listcomp>z"get_data_names.<locals>.<listcomp>   s    ---1---r   r   )getattrlenr   rangetolist)series_or_dataframenamesr   nvarss       r   get_data_namesr8   u   s    
 '66E >+Y== +Wqc::ZZ1__*=*CA*F--e---A::!HELr   c                 f    | D ]-}||         }||         }	||         }
 |j         ||	f|
d|d| .|S )z\
    Annotate Axes with labels, points, offset_points according to the
    given index.
    zoffset points)xytext
textcoordssize)annotate)r!   labelspointsoffset_pointsr<   r   kwargsilabelpointoffsets              r   annotate_axesrF      sl    
  ) )q	q	q!E5 	)O	) 	)!'	) 	) 	) 	)Ir   )N)NN)
__doc__statsmodels.compat.pythonr   __all__r   r   r   r   r8   rF   r-   r   r   <module>rJ      s    4 4 , , , , , ,,
-  + + + +\   :  2  &    r   