ó
šxŠ\c        	   @   s  d  d l  m Z d  d l m Z d  d l Z d  d l Z d  d l m Z d  d l	 m
 Z
 d  d l m Z m Z m Z d „  Z d d d „ Z d d	 d
 „ Z d e e e d d d d	 d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d d d d d „ Z d S(   iÿÿÿÿ(   t   division(   t   ceilN(   t   range(   t   is_list_like(   t   ABCDataFramet   ABCIndexClasst	   ABCSeriesc         C   si   yQ x. |  j  ƒ  D]  } | j d ƒ | j | ƒ q W|  j ƒ  } | j d d ƒ Wn t k
 rd n Xd  S(   Nt   rightt   bottomgš™™™™™É?(   t   get_xticklabelst   set_hat   set_rotationt
   get_figuret   subplots_adjustt	   Exception(   t   axt   rott   labelt   fig(    (    s5   lib/python2.7/site-packages/pandas/plotting/_tools.pyt   format_date_labels   s    c      	   K   s¬   t  | t ƒ r | j ƒ  } n t  | t ƒ r0 n t d ƒ ‚ | d k rT | j } n  | d k rl | j } n  | j } d d l	 } | j
 j
 |  d | d | d | | } | S(   sÊ  
    Helper function to convert DataFrame and Series to matplotlib.table

    Parameters
    ----------
    ax : Matplotlib axes object
    data : DataFrame or Series
        data for table contents
    kwargs : keywords, optional
        keyword arguments which passed to matplotlib.table.table.
        If `rowLabels` or `colLabels` is not specified, data index or column
        name will be used.

    Returns
    -------
    matplotlib table object
    s&   Input data must be DataFrame or SeriesiÿÿÿÿNt   cellTextt	   rowLabelst	   colLabels(   t
   isinstanceR   t   to_frameR   t
   ValueErrort   Nonet   indext   columnst   valuest   matplotlib.tablet   table(   R   t   dataR   R   t   kwargsR   t
   matplotlibR   (    (    s5   lib/python2.7/site-packages/pandas/plotting/_tools.pyR      s    	t   boxc   	      C   s  | d  k	 rBt | t t f ƒ s4 t | ƒ d k rC t d ƒ ‚ n  | \ } } d „  } | d k r™ | d k r™ | t |  ƒ | ƒ | f } \ } } nn | d k rÚ | d k rÚ | | t |  ƒ | ƒ f } \ } } n- | d k r| d k rd } t | ƒ ‚ n  | | |  k  r>t d j d | d	 | d
 |  ƒ ƒ ‚ n  | S| d k rRd S| d k rhd |  f S| d k r~|  d f Si d d 6d d 6d d 6d d 6} y | |  SWnd t k
 rd } x | d |  k  râ| d 7} qÅW| d | |  k r| | d f S| | f Sn Xd  S(   Ni   s)   Layout must be a tuple of (rows, columns)c         S   s   t  t |  ƒ ƒ S(   N(   t   intR   (   t   x(    (    s5   lib/python2.7/site-packages/pandas/plotting/_tools.pyt   <lambda>L   s    iÿÿÿÿi    s1   At least one dimension of layout must be positivesD   Layout of {nrows}x{ncols} must be larger than required size {nplots}t   nrowst   ncolst   nplotst   singlei   t
   horizontalt   verticali   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (	   R   R   t   tuplet   listt   lenR   t   floatt   formatt   KeyError(	   R)   t   layoutt   layout_typeR'   R(   t   ceil_t   msgt   layoutst   k(    (    s5   lib/python2.7/site-packages/pandas/plotting/_tools.pyt   _get_layoutD   s@    (	))

"c         K   sÔ  d d l  j }	 | d k r$ i  } n  | d k rB |	 j |   }
 nû t | ƒ râ t | ƒ } | d k	 ry t j d t ƒ n  | s… | rž t j d t d d ƒn  t	 | ƒ |  k rÊ | d j
 ƒ  }
 |
 | f St d j |  ƒ ƒ ‚ n  | j
 ƒ  }
 |  d	 k r| r
|
 | f S|
 t | ƒ f Sn  t j d
 t d d ƒ|
 j ƒ  t |  d | d | ƒ\ } } | | } t j | d t ƒ} |
 j | | d	 |  } | r¥| | d <n  | r¸| | d <n  | | d <xl t d	 | ƒ D][ } | j ƒ  } | |  k rd | d <d | d <n  |
 j | | | d	 |  } | | | <qÒW|  | k rbx" | |  D] } | j t ƒ qHWn  t | | |  | | | | ƒ | r¸| d	 k r| d } qÊ| j | | ƒ j ƒ  } n | j | | ƒ } |
 | f S(   sx	  Create a figure with a set of subplots already made.

    This utility wrapper makes it convenient to create common layouts of
    subplots, including the enclosing figure object, in a single call.

    Keyword arguments:

    naxes : int
      Number of required axes. Exceeded axes are set invisible. Default is
      nrows * ncols.

    sharex : bool
      If True, the X axis will be shared amongst all subplots.

    sharey : bool
      If True, the Y axis will be shared amongst all subplots.

    squeeze : bool

      If True, extra dimensions are squeezed out from the returned axis object:
        - if only one subplot is constructed (nrows=ncols=1), the resulting
        single Axis object is returned as a scalar.
        - for Nx1 or 1xN subplots, the returned object is a 1-d numpy object
        array of Axis objects are returned as numpy 1-d arrays.
        - for NxM subplots with N>1 and M>1 are returned as a 2d array.

      If False, no squeezing is done: the returned axis object is always
      a 2-d array containing Axis instances, even if it ends up being 1x1.

    subplot_kw : dict
      Dict with keywords passed to the add_subplot() call used to create each
      subplots.

    ax : Matplotlib axis object, optional

    layout : tuple
      Number of rows and columns of the subplot grid.
      If not specified, calculated from naxes and layout_type

    layout_type : {'box', 'horziontal', 'vertical'}, default 'box'
      Specify how to layout the subplot grid.

    fig_kw : Other keyword arguments to be passed to the figure() call.
        Note that all keywords not recognized above will be
        automatically included here.

    Returns:

    fig, ax : tuple
      - fig is the Matplotlib Figure object
      - ax can be either a single axis object or an array of axis objects if
      more than one subplot was created.  The dimensions of the resulting array
      can be controlled with the squeeze keyword, see above.

    **Examples:**

    x = np.linspace(0, 2*np.pi, 400)
    y = np.sin(x**2)

    # Just a figure and one subplot
    f, ax = plt.subplots()
    ax.plot(x, y)
    ax.set_title('Simple plot')

    # Two subplots, unpack the output array immediately
    f, (ax1, ax2) = plt.subplots(1, 2, sharey=True)
    ax1.plot(x, y)
    ax1.set_title('Sharing Y axis')
    ax2.scatter(x, y)

    # Four polar axes
    plt.subplots(2, 2, subplot_kw=dict(polar=True))
    iÿÿÿÿNs5   When passing multiple axes, layout keyword is ignoredsn   When passing multiple axes, sharex and sharey are ignored. These settings must be specified when creating axest
   stackleveli   i    sB   The number of passed axes must be {0}, the same as the output ploti   sS   To output multiple subplots, the figure containing the passed axes is being clearedR3   R4   t   dtypet   sharext   sharey(   t   matplotlib.pyplott   pyplotR   t   figureR   t   _flattent   warningst   warnt   UserWarningR/   R   R   R1   t   clearR9   t   npt   emptyt   objectt   add_subplotR   t   copyt   set_visiblet   Falset   _handle_shared_axest   reshapet   squeeze(   t   naxesR<   R=   RO   t
   subplot_kwR   R3   R4   t   fig_kwt   pltR   R'   R(   R)   t   axarrt   ax0t   it   kwdst   axes(    (    s5   lib/python2.7/site-packages/pandas/plotting/_tools.pyt	   _subplotss   sl    L		
	

	
	



c         C   sè   x! |  j  ƒ  D] } | j t ƒ q Wy– d d  l j } t |  j ƒ  | j ƒ rd |  j | j	 ƒ  ƒ n  t |  j
 ƒ  | j ƒ r• |  j | j d ƒ ƒ n  x! |  j ƒ  D] } | j t ƒ q¢ WWn t k
 rÐ ‚  n X|  j ƒ  j t ƒ d  S(   Niÿÿÿÿt    (   t   get_majorticklabelsRK   RL   t   matplotlib.tickert   tickerR   t   get_minor_locatort   NullLocatort   set_minor_locatort   AutoLocatort   get_minor_formattert   NullFormattert   set_minor_formattert   FormatStrFormattert   get_minorticklabelsR   t	   get_label(   t   axist   tR]   (    (    s5   lib/python2.7/site-packages/pandas/plotting/_tools.pyt   _remove_labels_from_axis  s    c   	      C   s¸  | d k r´| d k rHy¿ t  j | d | d f d t  j ƒ} x* |  D]" } | j ƒ  | | j | j f <qH Wxe |  D]] } | | j d | j f s› qu n  | sÂ t | j ƒ  j | ƒ ƒ d k ru t	 | j
 ƒ qu qu WWqHt k
 rDx[ |  D]O } | j ƒ  rqî n  | s-t | j ƒ  j | ƒ ƒ d k rî t	 | j
 ƒ qî qî WqHXn  | d k r´xZ |  D]O } | j ƒ  rsq[n  | sšt | j ƒ  j | ƒ ƒ d k r[t	 | j ƒ q[q[Wq´n  d  S(   Ni   R;   (   RF   t   zerost   boolt   get_visiblet   rowNumt   colNumR/   t   get_shared_x_axest   get_siblingsRj   t   xaxist
   IndexErrort   is_last_rowt   is_first_colt   get_shared_y_axest   yaxis(	   RT   R)   RP   R'   R(   R<   R=   R3   R   (    (    s5   lib/python2.7/site-packages/pandas/plotting/_tools.pyRM   *  s2    & 'c         C   sK   t  |  ƒ s t j |  g ƒ St |  t j t f ƒ r> |  j ƒ  St j |  ƒ S(   N(   R   RF   t   arrayR   t   ndarrayR   t   ravel(   RX   (    (    s5   lib/python2.7/site-packages/pandas/plotting/_tools.pyRA   T  s
    
c         C   sZ   |  j  ƒ  } t |  d ƒ r1 | |  j j  ƒ  7} n  t |  d ƒ rV | |  j j  ƒ  7} n  | S(   Nt   right_axt   left_ax(   t	   get_linest   hasattrR{   R|   (   R   t   lines(    (    s5   lib/python2.7/site-packages/pandas/plotting/_tools.pyt   _get_all_lines\  s    c         C   sq   t  j t  j } } xP |  D]H } | j d t ƒ } t t  j | ƒ | ƒ } t t  j | ƒ | ƒ } q W| | f S(   Nt   orig(   RF   t   inft	   get_xdataRL   t   mint   nanmint   maxt   nanmax(   R   t   leftR   t   lR%   (    (    s5   lib/python2.7/site-packages/pandas/plotting/_tools.pyt	   _get_xlimh  s    c         C   sÊ   d d  l  j } x´ t |  ƒ D]¦ } | d  k	 rJ | j | j ƒ  d | ƒn  | d  k	 rr | j | j ƒ  d | ƒn  | d  k	 rš | j | j ƒ  d | ƒn  | d  k	 r | j | j ƒ  d | ƒq q W|  S(   Niÿÿÿÿt   fontsizet   rotation(   R>   R?   RA   R   t   setpR	   t   get_yticklabels(   RX   t
   xlabelsizet   xrott
   ylabelsizet   yrotRS   R   (    (    s5   lib/python2.7/site-packages/pandas/plotting/_tools.pyt   _set_ticks_propsq  s     (   t
   __future__R    t   mathR   RB   t   numpyRF   t   pandas.compatR   t   pandas.core.dtypes.commonR   t   pandas.core.dtypes.genericR   R   R   R   R   R   R9   RL   t   TrueRY   Rj   RM   RA   R€   RŠ   R“   (    (    (    s5   lib/python2.7/site-packages/pandas/plotting/_tools.pyt   <module>   s$   	(/£		*				