ó
 m[c           @` s   d  Z  d d l m Z m Z m Z d d l Z d d l Z d d l Z d d l Z d d l	 Z
 d d l Z d d l m Z m Z m Z d d l m Z d d l j Z d d l m Z e j e  Z d e f d     YZ d	 e f d
     YZ d e f d     YZ d e f d     YZ d S(   sČ  
:mod:`~matplotlib.gridspec` is a module which specifies the location
of the subplot in the figure.

    `GridSpec`
        specifies the geometry of the grid that a subplot will be
        placed. The number of rows and number of columns of the grid
        need to be set. Optionally, the subplot layout parameters
        (e.g., left, right, etc.) can be tuned.

    `SubplotSpec`
        specifies the location of the subplot in the given `GridSpec`.

i    (   t   absolute_importt   divisiont   print_functionN(   t   _pylab_helperst   tight_layoutt   rcParams(   t   Bbox(   t   mplDeprecationt   GridSpecBasec           B` s}   e  Z d  Z d d d  Z d   Z d d d  Z d d d  Z d   Z d   Z	 d   Z
 d	   Z e d
  Z d   Z RS(   sm   
    A base class of GridSpec that specifies the geometry of the grid
    that a subplot will be placed.
    c         C` s1   | | |  _  |  _ |  j |  |  j |  d S(   sø   
        The number of rows and number of columns of the grid need to
        be set. Optionally, the ratio of heights and widths of rows and
        columns can be specified.
        N(   t   _nrowst   _ncolst   set_height_ratiost   set_width_ratios(   t   selft   nrowst   ncolst   height_ratiost   width_ratios(    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyt   __init__)   s    c         C` s   |  j  |  j f S(   s'   get the geometry of the grid, e.g., 2,3(   R	   R
   (   R   (    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyt   get_geometry3   s    c         C` s   d  S(   N(    (   R   t   figuret   fig(    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyt   get_subplot_params7   s    i   c         C` s4   | \ } } |  | | |  | | |  f } | S(   s:   
        create and return a SuplotSpec instance.
        (    (   R   t   loct   rowspant   colspant   loc1t   loc2t   subplotspec(    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyt   new_subplotspec:   s    $c         C` s=   | d  k	 r0 t |  |  j k r0 t d   n  | |  _ d  S(   NsT   Expected the given number of width ratios to match the number of columns of the grid(   t   Nonet   lenR
   t
   ValueErrort   _col_width_ratios(   R   R   (    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyR   B   s    !c         C` s   |  j  S(   N(   R!   (   R   (    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyt   get_width_ratiosH   s    c         C` s=   | d  k	 r0 t |  |  j k r0 t d   n  | |  _ d  S(   NsR   Expected the given number of height ratios to match the number of rows of the grid(   R   R   R	   R    t   _row_height_ratios(   R   R   (    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyR   K   s    !c         C` s   |  j  S(   N(   R#   (   R   (    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyt   get_height_ratiosQ   s    c         C` s>  |  j    \ } } | r? d } d } d } d } d }	 d }
 nE |  j |  } | j } | j } | j } | j } | j }	 | j }
 | | } | | } | | |
 | d } |
 | } |  j d k	 r| | t
 |  j  } g  |  j D] } | | ^ qč } n | g | } d g | g | d } t j t j | | g  j  } | | |	 | d } |	 | } |  j d k	 r°| | t
 |  j  } g  |  j D] } | | ^ q} n | g | } d g | g | d } t j t j | | g  j  } | | j d  j \ } } | | j d	  j \ } } | | | | f S(
   sō   
        return lists of bottom and top position of rows, left and
        right positions of columns.

        If raw=True, then these are all in units relative to the container
        with no margins.  (used for constrained_layout).
        g        g      š?i   i    i’’’’i   N(   i’’’’i   (   i’’’’i   (   R   R   t   leftt   rightt   bottomt   topt   wspacet   hspaceR#   R   t   sumt   npt   cumsumt   column_stackt   flatR!   t   reshapet   T(   R   R   t   rawR   R   R%   R&   R'   R(   R)   R*   t   subplot_paramst	   tot_widtht
   tot_heightt   cell_ht   sep_ht   normt   rt   cell_heightst   sep_heightst   cell_hst   cell_wt   sep_wt   cell_widthst
   sep_widthst   cell_wst   fig_topst   fig_bottomst	   fig_leftst
   fig_rights(    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyt   get_grid_positionsT   sH    							


#!
#!c   	      C` s¼   |  j    \ } } d   } t | t  r y | \ } } Wn t k
 rY t d   n Xt j | | |  | | |  g | | f  \ } } n | | | |  \ } } t |  | |  S(   s1   Create and return a SuplotSpec instance.
        c         S` s   t  |  t  rD |  j |  \ } } } | | k r | | d f Sn? |  d k  r] |  | 7}  n  d |  k ot | k  n r |  |  f St d   d  S(   Ni   i    s   invalid index(   t
   isinstancet   slicet   indicest
   IndexError(   t   keyt   sizet   startt   stopt   _(    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyt
   _normalize   s    
s   unrecognized subplot spec(   R   RG   t   tupleR    R,   t   ravel_multi_indext   SubplotSpec(	   R   RK   R   R   RP   t   k1t   k2t   num1t   num2(    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyt   __getitem__   s    	3N(   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R"   R   R$   t   FalseRF   RX   (    (    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyR   #   s   
					6t   GridSpecc        
   B` s   e  Z d  Z d d d d d d d d d d 	 Z d d d d d d g Z d   Z d	   Z d
   Z d d d  Z	 d   Z
 d d d d d d  Z RS(   sØ   
    A class that specifies the geometry of the grid that a subplot
    will be placed. The location of grid is determined by similar way
    as the SubplotParams.
    c         C` sĖ   | |  _  | |  _ | |  _ | |  _ | |  _ |	 |  _ | |  _ t j |  | | d |
 d | |  j d k s} |  j j
   r d |  _ n> |  j j   t j d |  j j d d t j   d |   |  _ d S(   sĄ  
        The number of rows and number of columns of the grid need to be set.
        Optionally, the subplot layout parameters (e.g., left, right, etc.)
        can be tuned.

        Parameters
        ----------
        nrows : int
            Number of rows in grid.

        ncols : int
            Number or columns in grid.

        Notes
        -----
        See `~.figure.SubplotParams` for descriptions of the layout parameters.
        R   R   t   parentt   namet   gridspect   artistN(   R%   R'   R&   R(   R)   R*   R   R   R   R   t   get_constrained_layoutt
   _layoutboxt   init_layoutboxt	   layoutboxt	   LayoutBoxt   seq_id(   R   R   R   R   R%   R'   R&   R(   R)   R*   R   R   (    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyR   Æ   s"    								R%   R'   R&   R(   R)   R*   c         C` s2   |  j  } y | j d  Wn t k
 r- n X| S(   NRc   (   t   __dict__t   popt   KeyError(   R   t   state(    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyt   __getstate__Ž   s    	c         C` s   | |  _  d  |  _ d  S(   N(   Rh   R   Rc   (   R   Rk   (    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyt   __setstate__ę   s    	c         K` s  xR t  j |  D]A \ } } | |  j k r> t |  | |  q t d | f   q WxBt  j t j j  D]+} x"| j	 j
 j D]} t | t j j  sQt | j t j j  rõ | j j   j   |  k rN| j j   | j | j j  qNqt | j t j j  r| j j   j   |  k rN| j j   | j | j j  qNqq | j   j   } | j   |  k r | j   | j | j  q q Wqk Wd S(   s   
        Update the current values.  If any kwarg is None, default to
        the current value, if set, otherwise to rc.
        s   %s is unknown keywordN(   t   sixt	   iteritemst   _AllowedKeyst   setattrt   AttributeErrort
   itervaluesR   t   Gcft   figst   canvasR   t   axesRG   t   mplt   SubplotBaset   _sharext   get_subplotspect   get_gridspect   update_paramst   _set_positiont   figboxt   _shareyt   get_topmost_subplotspec(   R   t   kwargst   kt   vt
   figmanagert   axt   ss(    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyt   updateė   s&    
c         ` s¤   | d k	 r t j d t  n  | d k r4 | } n  | d k rh d     j D } t j j |   } n t j | j	  }   f d     j D } | j
 |   | S(   s   
        Return a dictionary of subplot layout parameters. The default
        parameters are from rcParams unless a figure attribute is set.
        s2   the 'fig' kwarg is deprecated use 'figure' insteadc         S` s!   i  |  ] } t  d  | |  q S(   s   figure.subplot.(   R   (   t   .0R   (    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pys
   <dictcomp>  s   	 c         ` s"   i  |  ] } t    |  |  q S(    (   t   getattr(   R   R   (   R   (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pys
   <dictcomp>  s   	 N(   R   t   warningst   warnR   Rp   Rx   R   t   SubplotParamst   copyt   subplotparsR   (   R   R   R   t   kwR   t	   update_kw(    (   R   s2   lib/python2.7/site-packages/matplotlib/gridspec.pyR   
  s    	
	c         C` s)   g  |  j  D] } t |  |  r
 | ^ q
 S(   N(   Rp   R   (   R   R   (    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyt   locally_modified_subplot_params   s    gHįz®Gń?c   	      C` s   t  j | j d |  } d | k r4 t j d  n  | d k rR t  j |  } n  t  j | | j | | d | d | d | d | } |  j |   d S(   sy  
        Adjust subplot parameters to give specified padding.

        Parameters
        ----------

        pad : float
            Padding between the figure edge and the edges of subplots, as a
            fraction of the font-size.
        h_pad, w_pad : float, optional
            Padding (height/width) between edges of adjacent subplots.
            Defaults to ``pad_inches``.
        rect : tuple of 4 floats, optional
            (left, bottom, right, top) rectangle in normalized figure
            coordinates that the whole subplots area (including labels) will
            fit into.  Default is (0, 0, 1, 1).
        t	   grid_specsc   This figure includes Axes that are not compatible with tight_layout, so results might be incorrect.t   padt   h_padt   w_padt   rectN(	   R   t   get_subplotspec_listRw   R   R   R   t   get_renderert   get_tight_layout_figureR   (	   R   R   t   rendererR   R   R   R   t   subplotspec_listR   (    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyR   #  s    N(   RY   RZ   R[   R   R   Rp   Rl   Rm   R   R   R   R   (    (    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyR]   Ø   s   *				t   GridSpecFromSubplotSpecc           B` s;   e  Z d  Z d d d d d  Z d d d  Z d   Z RS(   sx   
    GridSpec whose subplot layout parameters are inherited from the
    location specified by a given SubplotSpec.
    c   	      C` s   | |  _  | |  _ | |  _ t j |  | | d | d | | j } | d k r[ d |  _ n/ | j | d | j d t	 j
   d |  |  _ d S(   s`  
        The number of rows and number of columns of the grid need to
        be set. An instance of SubplotSpec is also needed to be set
        from which the layout parameters will be inherited. The wspace
        and hspace of the layout can be optionally specified or the
        default values (from the figure or rcParams) will be used.
        R   R   R_   s	   .gridspecRa   N(   t   _wspacet   _hspacet   _subplot_specR   R   Rc   R   t   layout_from_subplotspecR_   Re   Rg   (	   R   R   R   t   subplot_specR)   R*   R   R   t	   subspeclb(    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyR   K  s    				c   
      C` s   | d
 k	 r t j d t  n  | d
 k r4 | } n  |  j d
 k	 rL |  j n | d
 k	 rd | j j n t d } |  j d
 k	 r |  j n | d
 k	 r | j j	 n t d } |  j
 j |  } | j \ } } } }	 t j j d | d | d | d |	 d | d	 |  S(   s:   Return a dictionary of subplot layout parameters.
        s2   the 'fig' kwarg is deprecated use 'figure' insteads   figure.subplot.hspaces   figure.subplot.wspaceR%   R&   R'   R(   R)   R*   N(   R   R   R   R   R   R   R*   R   R   R)   R    t   get_positiont   extentsRx   R   R   (
   R   R   R   R*   R)   R   R%   R'   R&   R(   (    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyR   g  s     	
	

c         C` s   |  j  j   S(   sA   Get the topmost SubplotSpec instance associated with the subplot.(   R    R   (   R   (    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyR   ~  s    N(   RY   RZ   R[   R   R   R   R   (    (    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyR   F  s
   RS   c           B` s   e  Z d  Z d d  Z d   Z d   Z d   Z d   Z d   Z	 e
 d  Z d   Z d	   Z e j rx d
   Z n  d   Z RS(   sC   Specifies the location of the subplot in the given `GridSpec`.
    c         C` su   | |  _  | |  _ | |  _ | j d k	 rh | j } t j d | d | j d t j   d |   |  _ n	 d |  _ d S(   sÖ   
        The subplot will occupy the num1-th cell of the given
        gridspec.  If num2 is provided, the subplot will span between
        num1-th cell and num2-th cell.

        The index starts from 0.
        R^   R_   s   .ssRa   N(	   t	   _gridspecRV   RW   Rc   R   Re   Rf   R_   Rg   (   R   R`   RV   RW   t   glb(    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyR     s    					c         C` s2   |  j  } y | j d  Wn t k
 r- n X| S(   NRc   (   Rh   Ri   Rj   (   R   Rk   (    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyRl     s    	c         C` s   | |  _  d  |  _ d  S(   N(   Rh   R   Rc   (   R   Rk   (    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyRm   §  s    	c         C` s   |  j  S(   N(   R¦   (   R   (    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyR|   ¬  s    c         C` s.   |  j    j   \ } } | | |  j |  j f S(   s”   
        Get the subplot geometry (``n_rows, n_cols, start, stop``).

        start and stop are the index of the start and stop of the
        subplot.
        (   R|   R   RV   RW   (   R   t   rowst   cols(    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyR   Æ  s    c         C` s   |  j    } | j   \ } } t |  j |  \ } } |  j d k	 r` t |  j |  \ } } n | } | } | | | | | | f S(   s   
        Get the subplot row and column numbers:
        (``n_rows, n_cols, row_start, row_stop, col_start, col_stop``)
        N(   R|   R   t   divmodRV   RW   R   (   R   R`   R   R   t	   row_startt	   col_startt   row_stopt   col_stop(    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyt   get_rows_columns¹  s    c         C` s’   |  j    } | j   \ } } t j |  j d k r? |  j g n |  j |  j g | | f  \ } } | j |  \ } }	 }
 } | | j   } |	 | j	   } |
 | j   } | | j	   } t
 j | | | |  } | r÷ | | d | d | | f S| Sd S(   sA   Update the subplot position from ``figure.subplotpars``.
        i    N(   R|   R   R,   t   unravel_indexRW   R   RV   RF   t   mint   maxR   t   from_extents(   R   R   t
   return_allR`   R   R   RØ   R©   RC   RB   RD   RE   t
   fig_bottomt   fig_topt   fig_leftt	   fig_rightR   (    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyR¤   Č  s    *c         C` s-   |  j    } t | d  r% | j   S|  Sd S(   s@   get the topmost SubplotSpec instance associated with the subplotR   N(   R|   t   hasattrR   (   R   R`   (    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyR   Ž  s    
c         C` sR   |  j  |  j |  j f t | d t    t | d t    t | d t    f k S(   NR¦   RV   RW   (   R¦   RV   RW   R   t   object(   R   t   other(    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyt   __eq__ę  s    c         C` s   |  | k S(   N(    (   R   R»   (    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyt   __ne__ī  s    c         C` s   t  |  j |  j |  j f  S(   N(   t   hashR¦   RV   RW   (   R   (    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyt   __hash__ń  s    N(   RY   RZ   R[   R   R   Rl   Rm   R|   R   RÆ   R\   R¤   R   R¼   Rn   t   PY2R½   Ræ   (    (    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyRS     s   				
				(   R[   t
   __future__R    R   R   Rn   R   t   loggingR   t   numpyR,   t
   matplotlibRx   R   R   R   t   matplotlib.transformsR   t   matplotlib._layoutboxRc   Re   t   matplotlib.cbookR   t	   getLoggerRY   t   _logRŗ   R   R]   R   RS   (    (    (    s2   lib/python2.7/site-packages/matplotlib/gridspec.pyt   <module>   s    =