
    G8c
                     ,    d Z ddlmZmZmZ ddZddZy)zE
Helper module for the *bbox_inches* parameter in `.Figure.savefig`.
    )BboxTransformedBboxAffine2DNc                      j                    j                   j                          j                  d        j                  j
                  g g t                j                  D ]  }j                  |j                                |j                  d      j                         }|j                  |fd       d|j                  v rj                  |j                         nj                         d	d|_          fd}| j                  }t!               j#                  |      }| j                  z  }t%        j&                  ddg|j(                    _        |j+                  |j,                        \  }}	 j                   j(                  |z  \  }
}t%        j&                  | |	 |
|       j                  _         j                  j/                          t1         j                  |       _          j2                  j5                  ||
z  |	|z   j                   j6                  |
z   j                   j8                  |z         |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 N )ar_poss      8/usr/lib/python3/dist-packages/matplotlib/_tight_bbox.py<lambda>zadjust_bbox.<locals>.<lambda>   s    4     apply_aspectc                      y r	   r
   )poss    r   r   zadjust_bbox.<locals>.<lambda>$   s    r   c                  T   t        j                        D ]%  \  } }}| j                  |       |
u r| `|| _        ' _        _        j                  	       j                  _        j                  j                          j                  j                  dddd       y )Nr      )zipaxesset_axes_locatorr   bboxbbox_inchesset_layout_enginetransFigure_boxout
invalidatepatch
set_bounds)axlocaspectr   figlocator_list
old_aspectorigBboxorigBboxInchesorig_layoutsentinels      r   restore_bboxz!adjust_bbox.<locals>.restore_bbox&   s    "388\:F 	)OBV$!O"(	) (k*")""$		Q1a(r   r   r	   )r   r   get_layout_enginer   r   r   objectr   appendget_axes_locatorget_positionfrozenr   __dict__r   dpir   scaler   from_boundssize	transformp0r   r   r   r    widthheight)r$   r   	fixed_dpir!   current_posr+   tr	dpi_scalex0y0w1h1r   r%   r&   r'   r(   r)   r*   s   `           @@@@@@@r   adjust_bboxrC      s    xxH__N'')K$oo%%GJLxHhh 	0B//12oouo5<<>
k?@R[[(boo.h'/	0) )  GG				)	$BCGG#I&&q!?k.>.>?CO\\+..)FBXX]]Y&FB"..sRCR@COOOO s3CHIIb"r'",chhoo.BD r   c                 <    |\  }} |        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.
    )rC   )r$   bbox_inches_restorer;   r   r+   r   s         r   process_figure_for_rasterizingrF   I   s+     !4KNCi0A>r   r	   )__doc__matplotlib.transformsr   r   r   rC   rF   r
   r   r   <module>rI      s    B A>Br   