B
    ]t\	                 @   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                sf  j jjj g g xZjD ]P}|jdd }|  |	  |fdd}|
| |d q$W  fdd}|dk	rt |}|j }nt j}d	}t||}	td
d
|j|j_|	j|	j }
}j j| j j|  }}t|
 | ||j_j  t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)Zoriginalc             S   s   |S )N )arposr   r   4lib/python3.7/site-packages/matplotlib/tight_bbox.py_l   s    zadjust_bbox.<locals>._lautoc                 sf   x0t jD ]\} }}| | | | qW __ j_j  j	
dddd d S )Nr      )zipaxes
set_aspectset_axes_locatorbboxbbox_inchestransFigure_boxout
invalidatepatch
set_bounds)axZaspZloc)r   asp_listfiglocator_listorigBboxorigBboxInchesr   r	   restore_bbox#   s    

z!adjust_bbox.<locals>.restore_bboxNg      ?r   )r   r   r   r   r   Zget_positionfrozenappendZget_axes_locatorZ
get_aspectr   r   r   ZscaleZdpir   r   Zfrom_boundswidthZheightx0y0r   r   r   )r   r   	fixed_dpir   r   r
   r   ZtrZ	dpi_scaleZ_bboxr"   r#   Zw1Zh1r   )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_rasterizingG   s    r&   )N)N)__doc__Zmatplotlib.transformsr   r   r   r%   r&   r   r   r   r	   <module>   s   
?