a
    Sic
                     @   s0   d Z ddlmZmZmZ dddZd	ddZdS )
zE
Helper module for the *bbox_inches* parameter in `.Figure.savefig`.
    )BboxTransformedBboxAffine2DNc                    sr  j j d jj g g t jD ]b}|	  |j
dd }||fdd d|jv r|j n
 ddd|_q: fdd	}|du rƈj}t |}|j }tjd
d
g|jR  _||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.
    NF)originalc                 S   s   |S N )ar_posr   r   R/var/www/html/django/DPS/env/lib/python3.9/site-packages/matplotlib/_tight_bbox.py<lambda>       zadjust_bbox.<locals>.<lambda>apply_aspectc                 S   s   d S r   r   )posr   r   r   r   $   r   c                     sv   t jD ](\} }}| | |u r0| `q|| _q__  j_j	  j
dddd d S )Nr      )zipaxesset_axes_locatorr   bboxbbox_inchesset_layout_enginetransFigure_boxout
invalidatepatch
set_bounds)axlocaspectr   figZlocator_listZ
old_aspectZorigBboxZorigBboxInchesZorig_layoutsentinelr   r   restore_bbox&   s    


z!adjust_bbox.<locals>.restore_bboxr   )N)r   r   get_layout_enginer   r   r   objectr   appendZget_axes_locatorget_positionfrozenr   __dict__r   dpir   scaler   from_boundssize	transformp0r   r   r   r   widthheight)r    r   	fixed_dpir   Zcurrent_posr"   trZ	dpi_scalex0y0w1h1r   r   r   adjust_bbox   s>    






r7   c                 C   s"   |\}}|  t | ||}||fS )z
    A function that needs 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.
    )r7   )r    bbox_inches_restorer1   r   r"   r	   r   r   r   process_figure_for_rasterizingI   s    r9   )N)N)__doc__matplotlib.transformsr   r   r   r7   r9   r   r   r   r   <module>   s   
A