
    h1                     b    S r SSKrSSKrSSKJrJr  SSKJ	r	  SSK
Jr   S	S jrS
S jr SS jrg)a  
Routines to adjust subplot params so that subplots are
nicely fit in the figure. In doing so, only axis labels, tick labels, Axes
titles and offsetboxes that are anchored to Axes are currently considered.

Internally, this module assumes that the margins (left margin, etc.) which are
differences between ``Axes.get_tightbbox`` and ``Axes.bbox`` are independent of
Axes position. This may fail if ``Axes.adjustable`` is ``datalim`` as well as
such cases as when left or right margin are affected by xlabel.
    N)_apiartist)FontProperties)Bboxc
                    Uu  p[        [        R                  S   S9R                  5       S-  nXl-  nUb  X|-  OUnUb  X-  OUn[	        U5      [	        U5      :w  d  [	        U5      S:X  a  [
        eU	c	  S=n=n=nnO#U	u  nnnnU(       a  SU-
  OSnU(       a  SU-
  OSn[        R                  " U
S-   U45      n[        R                  " XS-   45      nUcF  U VVs/ s H7  n[        R                  " U Vs/ s H  nUR                  SS9PM     sn5      PM9     nnn[        XEU5       GH`  u  nnu  nn[        S	 U 5       5      (       a  M$  / nU H5  nUR                  5       (       d  M  U[        R                  " UU5      /-  nM7     [        R                  " U5      nU R                   R#                  5       R%                  U5      nUUUR&                  4==   UR(                  UR(                  -
  -  ss'   UUUR*                  4==   UR,                  UR,                  -
  -  ss'   UUR&                  U4==   UR.                  UR.                  -
  -  ss'   UUR*                  U4==   UR0                  UR0                  -
  -  ss'   GMc     U R3                  5       u  n n!U(       d  [5        USS2S4   R5                  5       S5      UU -  -   nU R6                  n"U"(       ab  U"R9                  5       (       aM  U R                   R#                  5       R%                  U"R;                  U5      5      R<                  n#UU#UU -  -   -  nU(       d'  [5        USS2S
4   R5                  5       S5      UU -  -   nU(       d  [5        USSS24   R5                  5       S5      UU!-  -   nU R>                  (       av  U R>                  R9                  5       (       aW  U R                   R#                  5       R%                  U R>                  R;                  U5      5      R@                  n$UU$UU!-  -   -  nU(       d  [5        US
SS24   R5                  5       S5      UU!-  -   nU RB                  n"U"(       ab  U"R9                  5       (       aM  U R                   R#                  5       R%                  U"R;                  U5      5      R@                  n$UU$UU!-  -   -  nUU-   S:  a  [D        RF                  " S5        gUU-   S:  a  [D        RF                  " S5        g[I        USU-
  USU-
  S9n%US:  aX  USS2SS
24   R5                  5       UU -  -   n&SU-
  U-
  U&US-
  -  -
  U-  n'U'S:  a  [D        RF                  " S5        gU&U'-  U%S'   U
S:  aX  USS
2SS24   R5                  5       UU!-  -   n(SU-
  U-
  U(U
S-
  -  -
  U
-  n)U)S:  a  [D        RF                  " S5        gU(U)-  U%S'   U%$ s  snf s  snnf )a  
Return a dict of subplot parameters to adjust spacing between subplots
or ``None`` if resulting Axes would have zero height or width.

Note that this function ignores geometry information of subplot itself, but
uses what is given by the *shape* and *subplot_list* parameters.  Also, the
results could be incorrect if some subplots have ``adjustable=datalim``.

Parameters
----------
shape : tuple[int, int]
    Number of rows and columns of the grid.
span_pairs : list[tuple[slice, slice]]
    List of rowspans and colspans occupied by each subplot.
subplot_list : list of subplots
    List of subplots that will be used to calculate optimal subplot_params.
pad : float
    Padding between the figure edge and the edges of subplots, as a
    fraction of the font size.
h_pad, w_pad : float
    Padding (height/width) between edges of adjacent subplots, as a
    fraction of the font size.  Defaults to *pad*.
rect : tuple
    (left, bottom, right, top), default: None.
z	font.size)sizeH   Nr      T)originalc              3   J   #    U  H  oR                  5       (       + v   M     g 7fN)get_visible).0axs     J/var/www/html/env/lib/python3.13/site-packages/matplotlib/_tight_layout.py	<genexpr>+_auto_adjust_subplotpars.<locals>.<genexpr>L   s     7h>>###hs   !#zuTight layout not applied. The left and right margins cannot be made large enough to accommodate all Axes decorations.zuTight layout not applied. The bottom and top margins cannot be made large enough to accommodate all Axes decorations.)leftrightbottomtopznTight layout not applied. tight_layout cannot make Axes width small enough to accommodate all Axes decorationswspacezpTight layout not applied. tight_layout cannot make Axes height small enough to accommodate all Axes decorations.hspace)%r   mplrcParamsget_size_in_pointslen
ValueErrornpzerosr   unionget_positionzipallr   martist_get_tightbbox_for_layout_onlytransFigureinvertedtransform_bboxstartxminstopxmaxymaxyminget_size_inchesmax
_supylabelget_in_layoutget_window_extentwidth	_suptitleheight
_supxlabelr   warn_externaldict)*figrenderershape
span_pairssubplot_listax_bbox_listpadh_padw_padrectrowscolsfont_size_inchpad_inch	vpad_inch	hpad_inchmargin_leftmargin_bottommargin_right
margin_top_right_topvspaceshspacessubplotsr   ax_bboxrowspancolspanbbtight_bbox_raw
tight_bboxfig_width_inchfig_height_inchsuplabel	rel_width
rel_heightkwargsr   h_axesvspacev_axess*                                             r   _auto_adjust_subplotparsrd      s   8 JD$\\+&((:(:(<rBN#H*/*;&I*/*;&I
:#l++s</@A/E|BFFFmFlZ370]FD%+q6z!%QX4
hhq$'(GhhQh'(G )*( JJJ26JK( 	 * 25
24-'-GW7h777B~~w==b(KLL  B__--/>>~N
&'7<<*//+II'%&*//GLL*HH&w&':??W\\+II'g%&',,*HH&!24$ '*&9&9&;#NO '!Q$-++-q1H^4KK>>..00002AA**8466;e 9x'>>>K71b5>--/3h~6MMA**,a08O3KK
==S]]88::113BB//9;;A6 *x'???JGBEN..0!4x7OO>>..00113BB**8466<f Z(?*BBBM\!Q& ? 	@ z!Q& ? 	@ {L(&*n&F
 axAbD!%%')n*DDl"[06TAX3FF$NA:  B C %F8ax2q!%%')o*EEj.=06TAX3FF$NA:  C D %F8Mm K*s   W"9WW"W"c                 :   / nU  H  nUR                  5       nUc  Un[        US5      (       aV  UR                  5       nUbB  UR                  5       nUR	                  5       nUb  Xa:w  a  SnOUR                  5       (       a  SnOSnUR                  U5        M     U$ )z
Return a list of subplotspec from the given list of Axes.

For an instance of Axes that does not support subplotspec, None is inserted
in the list.

If grid_spec is given, None is inserted for those not from the given
grid_spec.
Nget_subplotspec)get_axes_locatorhasattrrf   get_topmost_subplotspecget_gridspeclocally_modified_subplot_paramsappend)	axes_list	grid_specsubplotspec_listr   axes_or_locatorsubplotspecgss          r   get_subplotspec_listrs      s     --/" O?$566)99;K&)AAC --/(&*7799"&KK,% (     c                    U Vs0 s H  o/ _M     n	n[        X5       H  u  pX   R                  U
5        M     U	R                  SS5      (       a  [        R                  " S5        U	(       d  0 $ [        U	R                  5       5      nU	 Vs/ s H  oR                  U 5      PM     nn[        S U	 5       5      n[        S U	 5       5      n/ nU	 GH  nUR                  5       R                  5       u  nn[        UU5      u  nn[        UU5      u  nnUS:w  a  [        R                  " S5        0 s  $ US:w  a  [        R                  " S5        0 s  $ UR                  [        UR                  R                  U-  UR                  R                  U-  5      [        UR                   R                  U-  UR                   R                  U-  5      45        GM	     [#        XX4UUUXEUS9	nUbQ  UbN  Uu  nnnnUb  UUS	   -  nUb  UUS
   -  nUb  USUS   -
  -  nUb  USUS   -
  -  n[#        XX4UUUXEUUUUU4S9
nU$ s  snf s  snf )a6  
Return subplot parameters for tight-layouted-figure with specified padding.

Parameters
----------
fig : Figure
axes_list : list of Axes
subplotspec_list : list of `.SubplotSpec`
    The subplotspecs of each Axes.
renderer : renderer
pad : float
    Padding between the figure edge and the edges of subplots, as a
    fraction of the font size.
h_pad, w_pad : float
    Padding (height/width) between edges of adjacent subplots.  Defaults to
    *pad*.
rect : tuple (left, bottom, right, top), default: None.
    rectangle in normalized figure coordinates
    that the whole subplots area (including labels) will fit into.
    Defaults to using the entire figure.

Returns
-------
subplotspec or None
    subplotspec kwargs to be passed to `.Figure.subplots_adjust` or
    None if tight_layout could not be accomplished.
NzcThis figure includes Axes that are not compatible with tight_layout, so results might be incorrect.c              3   T   #    U  H  oR                  5       R                  v   M      g 7fr   )rj   nrowsr   sss     r   r   *get_tight_layout_figure.<locals>.<genexpr>        EnOO%++n   &(c              3   T   #    U  H  oR                  5       R                  v   M      g 7fr   )rj   ncolsrx   s     r   r   rz      r{   r|   r   zdtight_layout not applied: number of rows in subplot specifications must be multiples of one another.zgtight_layout not applied: number of columns in subplot specifications must be multiples of one another.)r>   r?   r@   rA   rB   rC   rD   r   r   r
   r   r   )r>   r?   r@   rA   rB   rC   rD   rE   )r$   rl   popr   r:   listvaluesr#   r2   rj   get_geometrydivmodslicerV   r+   r-   rW   rd   )r<   rm   ro   r=   rB   rC   rD   rE   ry   ss_to_subplotsr   r@   rA   	max_nrows	max_ncolsr?   rF   rG   div_rowmod_rowdiv_colmod_colr`   r   r   r   r   s                              r   get_tight_layout_figurer      s   @ (88'7"f'7N8i2!!"% 3$%%;	< 	--/0L3AB>ROOC(>LBEnEEIEnEEIJ __&335
d!)T2!)T2a<  ; < Ia<  ; < I"**""W,bjjoo.GH"**""W,bjjoo.GHJ 	K) 0 &c-6,B1;3?3?*-%IF F. $( feSF6N"DfX&&Fa&/)*E?Au%&C)#1:0F5?7C7C.1e04feS/IK MW 9 Cs   II)NHzG?NNNr   )r   NNN)__doc__numpyr    
matplotlibr   r   r   r&   matplotlib.font_managerr   matplotlib.transformsr   rd   rs   r    rt   r   <module>r      s<   	   . 2 &
 CGIXF DHkrt   