
    !g                     D    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	y)z.Helper functions for graphics with Matplotlib.    )lrangecreate_mpl_axcreate_mpl_figc                  4    	 ddl m}  | S #  t        d      xY w)z6This function is not needed outside this utils module.r   NzMatplotlib is not found.)matplotlib.pyplotpyplotImportError)plts    W/var/www/dash_apps/app1/venv/lib/python3.12/site-packages/statsmodels/graphics/utils.py_import_mplr      s$    6' J6455s   
 Nc                     | /t               }|j                         }|j                  d      } || fS | 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)
    o   )r   figureadd_subplot)axr
   figs      r   r   r      sI    H 
zmjjl__S! 7N ii7N    c                 B    | t               }|j                  |      } | 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
    )figsize)r   r   )r   r   r
   s      r   r   r   ?   s%    , {mjjj)Jr   c                    | "t        |j                  j                  d         } t        | t              r|j
                  |    }| }||fS t        | t        t        f      r@g }g }| D ]3  }t        ||      \  }}|j                  |       |j                  |       5 ||fS | }|j
                  j                  |       }||fS )zr
    Give a name or an integer and return the name and integer location of the
    column in a design matrix.
       )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    
 {UZZ%%a()#s$$S)	 h 
C%	'	 	+D,=dE,J)NM^,OOM*	+ h 	##))#.hr   c                    t        | dd      }|st        | dd      }|sQt        | ddg      }t        |      dk(  rdn| j                  d   }t        |      D cg c]  }d }}|dk(  r|d   }|S |j	                         }|S c c}w )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   zX%dr   )getattrlenr   rangetolist)series_or_dataframenamesr   nvars_s        r   get_data_namesr4   u   s    
 '6E+Y=+Wqc:Z1_*=*C*CA*F %e-1--A:!HE L L .s   	Bc                 b    | 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_pointsr8   r   kwargsilabelpointoffsets              r   annotate_axesrB      s\    
  )q	q	q!E5 	)O	)!'	)	) Ir   )N)NN)
__doc__statsmodels.compat.pythonr   __all__r   r   r   r   r4   rB    r   r   <module>rG      s5    4 ,,
-+\:2&r   