ó
áp7]c           @   sq   d  Z  d d l m Z m Z m Z d d g Z d „  Z d d „ Z d d d „ Z	 d „  Z
 d	 „  Z d
 „  Z d S(   s.   Helper functions for graphics with Matplotlib.iÿÿÿÿ(   t   lranget   ranget   longt   create_mpl_axt   create_mpl_figc          C   s-   y d d l  j }  Wn t d ƒ ‚ n X|  S(   s6   This function is not needed outside this utils module.iÿÿÿÿNs   Matplotlib is not found.(   t   matplotlib.pyplott   pyplott   ImportError(   t   plt(    (    s9   lib/python2.7/site-packages/statsmodels/graphics/utils.pyt   _import_mpl   s
    c         C   sF   |  d k r3 t ƒ  } | j ƒ  } | j d ƒ }  n	 |  j } | |  f S(   s  Helper function for when a single plot axis is needed.

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

    Returns
    -------
    fig : Matplotlib figure instance
        If `ax` is None, the created figure.  Otherwise the figure to which
        `ax` is connected.
    ax : Matplotlib AxesSubplot instance
        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)

    io   N(   t   NoneR	   t   figuret   add_subplot(   t   axR   t   fig(    (    s9   lib/python2.7/site-packages/statsmodels/graphics/utils.pyR      s    %		c         C   s.   |  d k r* t ƒ  } | j d | ƒ }  n  |  S(   s  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 : Matplotlib figure instance, optional
        If given, this figure is simply returned.  Otherwise a new figure is
        created.

    Returns
    -------
    fig : Matplotlib figure instance
        If `fig` is None, the created figure.  Otherwise the input `fig` is
        returned.

    See Also
    --------
    create_mpl_ax

    t   figsizeN(   R
   R	   R   (   R   R   R   (    (    s9   lib/python2.7/site-packages/statsmodels/graphics/utils.pyR   @   s    	c         C   sÖ   |  d k r% t | j j d ƒ }  n  t |  t t f ƒ rP | j |  } |  } n| t |  t t	 f ƒ r´ g  } g  } xX |  D]5 } t
 | | ƒ \ } } | j | ƒ | j | ƒ qx Wn |  } | j j |  ƒ } | | f S(   sr   
    Give a name or an integer and return the name and integer location of the
    column in a design matrix.
    i   N(   R
   R    t   exogt   shapet
   isinstancet   intR   t
   exog_namest   tuplet   listt   maybe_name_or_idxt   appendt   index(   t   idxt   modelt	   exog_namet   exog_idxt   itemt   exog_name_itemt   exog_idx_item(    (    s9   lib/python2.7/site-packages/statsmodels/graphics/utils.pyR   ^   s    	c         C   s¸   t  |  d d ƒ } | s- t  |  d d ƒ } n  | s¨ t  |  d d g ƒ } t | ƒ d k r` d n
 |  j d } g  t | ƒ D] } d ^ qz } | d k r´ | d } q´ n | j ƒ  } | S(   s•   
    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.
    t   namet   columnsR   i   s   X%di    N(   t   getattrR
   t   lenR   R   t   tolist(   t   series_or_dataframet   namesR   t   nvarst   _(    (    s9   lib/python2.7/site-packages/statsmodels/graphics/utils.pyt   get_data_namesw   s    %c         K   sX   xQ |  D]I } | | } | | }	 | | }
 | j  | |	 d |
 d d d | | q W| S(   s\   
    Annotate Axes with labels, points, offset_points according to the
    given index.
    t   xytextt
   textcoordss   offset pointst   size(   t   annotate(   R   t   labelst   pointst   offset_pointsR-   R   t   kwargst   it   labelt   pointt   offset(    (    s9   lib/python2.7/site-packages/statsmodels/graphics/utils.pyt   annotate_axesŠ   s    


N(   t   __doc__t   statsmodels.compat.pythonR    R   R   t   __all__R	   R
   R   R   R   R*   R7   (    (    (    s9   lib/python2.7/site-packages/statsmodels/graphics/utils.pyt   <module>   s   	
/		