ó
O‰ŽRc           @   s·   d  Z  d d l Z d d l Z d d l m Z m Z d d l m Z e j Z d „  Z	 d „  Z
 d „  Z d „  Z d d	 d d d d
 „ Z d „  Z d d „ Z d	 d d d d „ Z d S(   sâ  
This module provides routines to adjust subplot params so that subplots are
nicely fit in the figure. In doing so, only axis labels, tick labels and axes
titles are currently considered.

Internally, it assumes that the margins (left_margin, etc.) which are
differences between ax.get_tightbbox and ax.bbox are independent of axes
position. This may fail if Axes.adjustable is datalim. Also, This will fail
for some cases (for example, left or right margin is affected by xlabel).
iÿÿÿÿN(   t   TransformedBboxt   Bbox(   t   FontPropertiesc         C   s   | j  |  j  S(   N(   t   xmin(   t
   tight_bboxt	   axes_bbox(    (    sQ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/tight_layout.pyt	   _get_left   s    c         C   s   |  j  | j  S(   N(   t   xmax(   R   R   (    (    sQ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/tight_layout.pyt
   _get_right   s    c         C   s   | j  |  j  S(   N(   t   ymin(   R   R   (    (    sQ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/tight_layout.pyt   _get_bottom   s    c         C   s   |  j  | j  S(   N(   t   ymax(   R   R   (    (    sQ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/tight_layout.pyt   _get_top!   s    gHáz®Gñ?c
   .   
   C   s¢  | \ }
 } | t  d t d ƒ j ƒ  d } | d	 k	 r] | t  d t d ƒ j ƒ  d } n | } | d	 k	 r“ | t  d t d ƒ j ƒ  d } n | } t | ƒ d k rº t d ƒ ‚ n  t | ƒ t | ƒ k rá t d ƒ ‚ n  |	 d	 k rd	 } d	 } d	 } d	 } nD |	 \ } } } } | r-d | } n d	 } | rFd | } n d	 } g  t |
 d | ƒ D] } g  ^ qa} g  t |
 | d ƒ D] } g  ^ qˆ} t j } | d	 k rg  } xI | D]> } | g  | D] } | j	 d t
 ƒ ^ qÌƒ } | j | ƒ q¼Wn  xt | | | ƒ D]ú\ } } \ } } | g  | D] } | j | ƒ ^ q3ƒ } t | |  j j ƒ  ƒ } t | | ƒ \ }  }! | d	 k r%| |  | d |! j t | | ƒ ƒ | |  | d |! d j t | | ƒ ƒ | |  | |! j t | | ƒ ƒ | |  d | |! j t | | ƒ ƒ qt | | ƒ \ }" }# xk t |  |" d ƒ D]V }$ | |$ | d |! j t | | ƒ ƒ | |$ | d |# d j t | | ƒ ƒ qNWxc t |! |# d ƒ D]N }% | |  | |% j t | | ƒ ƒ | |" d | |% j t | | ƒ ƒ q¼WqW|  j ƒ  \ }& }' | sxt g  | d	 d	 | d … D] }( t |( ƒ ^ qEd g ƒ } | | |& 7} n  | sÌt g  | | d	 | d … D] }( t |( ƒ ^ q™d g ƒ } | | |& 7} n  | st g  | |  D] }( t |( ƒ ^ qàd g ƒ } | | |' 7} n  | s[t g  | | D] }( t |( ƒ ^ q(d g ƒ } | | |' 7} n  t d
 | d d | d | d d | ƒ }) | d k r(t g  t |
 ƒ D]B } | | | d d | d | d d !D] }( t |( ƒ ^ qÍq ƒ }* |* | |& 7}* d | | |* | d | }+ |* |+ |) d <n  |
 d k ržt g  | | | !D] }( t |( ƒ ^ qFƒ }, |, | |' 7}, d | | |, |
 d |
 }- |, |- |) d <n  |) S(   s«  
    Return a dictionary of subplot parameters so that spacing between
    subplots are adjusted. Note that this function ignore geometry
    information of subplot itself, but uses what is given by
    *nrows_ncols* and *num1num2_list* parameteres. Also, the results could be
    incorrect if some subplots have ``adjustable=datalim``.

    Parameters:

    nrows_ncols
      number of rows and number of columns of the grid.

    num1num2_list
      list of numbers specifying the area occupied by the subplot

    subplot_list
      list of subplots that will be used to calcuate optimal subplot_params.

    pad : float
      padding between the figure edge and the edges of subplots, as a fraction
      of the font-size.
    h_pad, w_pad : float
      padding (height/width) between edges of adjacent subplots.
        Defaults to `pad_inches`.

    rect
      [left, bottom, right, top] in normalized (0, 1) figure coordinates.
    t   sizes	   font.sizeg      R@i    t    g      ð?i   t   originalNt   leftt   rightt   bottomt   topt   wspacet   hspace(   R   t   rcParamst   get_size_in_pointst   Nonet   lent   RuntimeErrort   rangeR   t   uniont   get_positiont   Truet   appendt   zipt   get_tightbboxR    t   transFiguret   invertedt   divmodR   R   R   R
   t   get_size_inchest   maxt   sumt   dict(.   t   figt   renderert   nrows_ncolst   num1num2_listt   subplot_listt   ax_bbox_listt   padt   h_padt   w_padt   rectt   rowst   colst
   pad_inchest   vpad_inchest   hpad_inchest   margin_leftt   margin_bottomt   margin_rightt
   margin_topt   _rightt   _topt   it   vspacest   hspacesR   t   subplotst   axt   ax_bboxt   num1t   num2t   tight_bbox_rawR   t   row1t   col1t   row2t   col2t   row_it   col_it   fig_width_incht   fig_height_incht   st   kwargsR   t   h_axest   vspacet   v_axes(    (    sQ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/tight_layout.pyt   auto_adjust_subplotpars%   s¸    #!$$	''	%	(==01
E-c         C   s{   |  j  r |  j  } nb |  j } | rB t | d ƒ rB | j ƒ  } n5 t j d ƒ d d l m } | |  ƒ } | j ƒ  } | S(   Nt   get_renderers+   tight_layout : falling back to Agg rendereriÿÿÿÿ(   t   FigureCanvasAgg(   t   _cachedRenderert   canvast   hasattrRU   t   warningst   warnt   matplotlib.backends.backend_aggRV   (   R)   R*   RX   RV   (    (    sQ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/tight_layout.pyRU   ×   s    		c         C   s¾   g  } x± |  D]© } | j  ƒ  } | d k r4 | } n  t | d ƒ r£ | j ƒ  } | j ƒ  } | j ƒ  } | d k	 r‹ | | k r  d } q  q© | j ƒ  r© d } q© n d } | j | ƒ q W| S(   sÿ   
    Return a list of subplotspec from the given list of axes.  For an
    instance of axes that does not support subplotspec, None is
    inserted in the list.

    If grid_spec is given, None is inserted for those not from
    the given grid_spec.

    t   get_subplotspecN(   t   get_axes_locatorR   RY   R]   t   get_topmost_subplotspect   get_gridspect   locally_modified_subplot_paramsR   (   t	   axes_listt	   grid_spect   subplotspec_listRB   t   axes_or_locatort   subplotspect   gs(    (    sQ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/tight_layout.pyt   get_subplotspec_listé   s"    
	c   (      C   s2  g  } g  }	 g  }
 g  } i  } g  } x¹ t  | | ƒ D]¨ \ } } | d k rR q4 n  | j | g  ƒ } | sÏ | j ƒ  \ } } } } |	 j | ƒ |
 j | ƒ | j | ƒ | j | ƒ | j | j |  ƒ ƒ n  | j | ƒ q4 Wt |	 ƒ } t |
 ƒ } g  } x | D]ø } | j ƒ  \ } } } } t | | ƒ \ } } t | | ƒ \ } } | d k se| d k rtt d ƒ ‚ n  t | | ƒ \ } }  | d k r¥| |  }! }" n t | | ƒ \ }! }" | j | | | |  | |! d | d | |" d | d f ƒ qWt	 |  | d | | f d | d | d | d | d	 | d
 | ƒ}# | d k	 r.| \ }$ }% }& }' |$ d k	 r{|$ |# d 7}$ n  |% d k	 r˜|% |# d 7}% n  |& d k	 r¹|& d |# d 8}& n  |' d k	 rÚ|' d |# d 8}' n  t	 |  | d | | f d | d | d | d | d	 | d
 | d |$ |% |& |' f ƒ}# n  |# S(   s+  
    Return subplot parameters for tight-layouted-figure with specified
    padding.

    Parameters:

      *fig* : figure instance

      *axes_list* : a list of axes

      *subplotspec_list* : a list of subplotspec associated with each
        axes in axes_list

      *renderer* : renderer instance

      *pad* : float
        padding between the figure edge and the edges of subplots,
        as a fraction of the font-size.

      *h_pad*, *w_pad* : float
        padding (height/width) between edges of adjacent subplots.
        Defaults to `pad_inches`.

      *rect* : if rect is given, it is interpreted as a rectangle
        (left, bottom, right, top) in the normalized figure
        coordinate that the whole subplots area (including
        labels) will fit into. Default is (0, 0, 1, 1).
    i    R   i   R+   R,   R-   R.   R/   R0   R1   R   R   R   R   R2   N(
   R    R   t
   setdefaultt   get_geometryR   R   R&   R$   R   RT   ((   R)   Rb   Rd   R*   R/   R0   R1   R2   R-   t
   nrows_listt
   ncols_listR.   t   subplot_dictt   subplotspec_list2RB   Rf   RA   t   myrowst   mycolst   _t	   max_nrowst	   max_ncolsR,   R3   R4   RD   RE   t   div_rowt   mod_rowt   div_colt   mod_colt   rowNum1t   colNum1t   rowNum2t   colNum2RP   R   R   R   R   (    (    sQ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/tight_layout.pyt   get_tight_layout_figure
  sv    	.	(   t   __doc__RZ   t
   matplotlibt   matplotlib.transformsR    R   t   matplotlib.font_managerR   R   R   R   R
   R   R   RT   RU   Rh   R|   (    (    (    sQ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/tight_layout.pyt   <module>
   s   						¬	"