3
$ßL]
  ã               @   s0   d Z ddlmZmZmZ ddd„Zd	dd„ZdS )
zD
This module is to support *bbox_inches* option in savefig command.
é    )ÚBboxÚTransformedBboxÚAffine2DNc                sz  ˆj ‰ˆj‰ˆjƒ ‰ˆjj‰ ˆjdƒ g ‰g ‰xZˆjD ]P}|jdd�jƒ }ˆj	|j
ƒ ƒ ˆj	|jƒ ƒ |fdd„}|j|ƒ |jdƒ q6W ‡ ‡‡‡‡‡‡fd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 )aO  
    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.
    F)Úoriginalc             S   s   |S )N© )ÚaÚrÚposr   r   ú=/tmp/pip-install-edjban26/matplotlib/matplotlib/tight_bbox.pyÚ_l!   s    zadjust_bbox.<locals>._lÚautoc                 sp   x0t ˆjˆˆƒD ]\} }}| j|ƒ | j|ƒ qW ˆˆ_ˆˆ_ˆjˆƒ ˆ ˆj_ˆjj	ƒ  ˆj
jddddƒ d S )Nr   é   )ÚzipÚaxesÚ
set_aspectÚset_axes_locatorÚbboxÚbbox_inchesÚset_tight_layoutÚtransFigureÚ_boxoutÚ
invalidateÚpatchÚ
set_bounds)ÚaxZaspÚloc)r   Úasp_listÚfigÚlocator_listÚorigBboxÚorigBboxInchesÚorig_tight_layoutr   r
   Úrestore_bbox&   s    


z!adjust_bbox.<locals>.restore_bboxNg      ð?r   )r   r   Zget_tight_layoutr   r   r   r   Úget_positionÚfrozenÚappendZget_axes_locatorZ
get_aspectr   r   r   ZscaleZdpir   r   Zfrom_boundsÚwidthÚheightÚx0Úy0r   r   r   )r   r   Ú	fixed_dpir   r	   r   r"   ÚtrZ	dpi_scaleZ_bboxr(   r)   Zw1Úh1r   )r   r   r   r   r   r    r!   r
   Úadjust_bbox   s>    



r-   c             C   s"   |\}}|ƒ  t | ||ƒ}||fS )z 
    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.
    )r-   )r   Zbbox_inches_restorer*   r   r"   r   r   r   r
   Úprocess_figure_for_rasterizingJ   s    r.   )N)N)Ú__doc__Zmatplotlib.transformsr   r   r   r-   r.   r   r   r   r
   Ú<module>   s   
B