ó
 m[c           @` sl   d  Z  d d l m Z m Z m Z m Z d d l Z d d l m Z m	 Z	 m
 Z
 d d „ Z d d „ Z d S(   uD   
This module is to support *bbox_inches* option in savefig command.
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   Bboxt   TransformedBboxt   Affine2Dc         ` sè  ˆ j  ‰ ˆ j ‰ ˆ j j ‰  g  ‰ g  ‰ xu ˆ j D]j } | j d t ƒ j ƒ  } ˆ j | j	 ƒ  ƒ ˆ j | j
 ƒ  ƒ | d „ } | j | ƒ | j d ƒ q4 W‡  ‡ ‡ ‡ ‡ ‡ f d †  } | d k	 rî t ƒ  j | ƒ } | ˆ j } n t ƒ  j ˆ j ƒ } d } t | | ƒ }	 t j d d | j | j ƒ ˆ _ |	 j |	 j }
 } ˆ j  j | ˆ j  j | } } t j |
 | | | ƒ ˆ j _ ˆ j j ƒ  t ˆ j | ƒ ˆ _  ˆ j j |
 | | | ˆ j  j | ˆ j  j | ƒ | S(   uO  
    Temporarily adjust the figure so that only the specified area
    (bbox_inches) is saved.

    It modifies fig.bbox, fig.bbox_inches,
    fig.transFigure._boxout, and fig.patch.  While the figure size
    changes, the scale of the original figure is conserved.  A
    function which restores the original values are returned.
    t   originalc         S` s   | S(   N(    (   t   at   rt   pos(    (    s4   lib/python2.7/site-packages/matplotlib/tight_bbox.pyt   _l#   s    u   autoc          ` s‹   x@ t  ˆ j ˆ ˆ ƒ D]) \ }  } } |  j | ƒ |  j | ƒ q Wˆ ˆ _ ˆ ˆ _ ˆ  ˆ j _ ˆ j j ƒ  ˆ j	 j
 d d d d ƒ d  S(   Ni    i   (   t   zipt   axest
   set_aspectt   set_axes_locatort   bboxt   bbox_inchest   transFiguret   _boxoutt
   invalidatet   patcht
   set_bounds(   t   axt   aspt   loc(   R   t   asp_listt   figt   locator_listt   origBboxt   origBboxInches(    s4   lib/python2.7/site-packages/matplotlib/tight_bbox.pyt   restore_bbox(   s    %		g      ð?i    N(   R   R   R   R   R   t   get_positiont   Falset   frozent   appendt   get_axes_locatort
   get_aspectR   R   t   NoneR   t   scalet   dpiR   R   t   from_boundst   widtht   heightt   x0t   y0R   R   R   (   R   R   t	   fixed_dpiR   R
   R   R   t   trt	   dpi_scalet   _bboxR,   R-   t   w1t   h1(    (   R   R   R   R   R   R   s4   lib/python2.7/site-packages/matplotlib/tight_bbox.pyt   adjust_bbox   s:    		! c         C` s/   | \ } } | ƒ  t  |  | | ƒ } | | f S(   u    
    This need to be called when figure dpi changes during the drawing
    (e.g., rasterizing). It recovers the bbox and re-adjust it with
    the new dpi.
    (   R4   (   R   t   bbox_inches_restoreR.   R   R   R	   (    (    s4   lib/python2.7/site-packages/matplotlib/tight_bbox.pyt   process_figure_for_rasterizingL   s    (   t   __doc__t
   __future__R    R   R   R   t   sixt   matplotlib.transformsR   R   R   R&   R4   R6   (    (    (    s4   lib/python2.7/site-packages/matplotlib/tight_bbox.pyt   <module>   s
   "?