
    h+                         S r SSKJr  SSKrSSKJr  SSKJrJ	r	   " S S5      r
 " S S	\
5      r " S
 S\
5      r " S S\
5      rg)a1  
Classes to layout elements in a `.Figure`.

Figures have a ``layout_engine`` property that holds a subclass of
`~.LayoutEngine` defined here (or *None* for no layout).  At draw time
``figure.get_layout_engine().execute()`` is called, the goal of which is
usually to rearrange Axes on the figure to produce a pleasing layout. This is
like a ``draw`` callback but with two differences.  First, when printing we
disable the layout engine for the final draw. Second, it is useful to know the
layout engine while the figure is being created.  In particular, colorbars are
made differently with different layout engines (for historical reasons).

Matplotlib supplies two layout engines, `.TightLayoutEngine` and
`.ConstrainedLayoutEngine`.  Third parties can create their own layout engine
by subclassing `.LayoutEngine`.
    )nullcontextN)do_constrained_layout)get_subplotspec_listget_tight_layout_figurec                   f   ^  \ rS rSrSrSrSrU 4S jrS r\	S 5       r
\	S 5       rS rS	 rS
rU =r$ )LayoutEngine   au  
Base class for Matplotlib layout engines.

A layout engine can be passed to a figure at instantiation or at any time
with `~.figure.Figure.set_layout_engine`.  Once attached to a figure, the
layout engine ``execute`` function is called at draw time by
`~.figure.Figure.draw`, providing a special draw-time hook.

.. note::

   However, note that layout engines affect the creation of colorbars, so
   `~.figure.Figure.set_layout_engine` should be called before any
   colorbars are created.

Currently, there are two properties of `LayoutEngine` classes that are
consulted while manipulating the figure:

- ``engine.colorbar_gridspec`` tells `.Figure.colorbar` whether to make the
   axes using the gridspec method (see `.colorbar.make_axes_gridspec`) or
   not (see `.colorbar.make_axes`);
- ``engine.adjust_compatible`` stops `.Figure.subplots_adjust` from being
    run if it is not compatible with the layout engine.

To implement a custom `LayoutEngine`:

1. override ``_adjust_compatible`` and ``_colorbar_gridspec``
2. override `LayoutEngine.set` to update *self._params*
3. override `LayoutEngine.execute` with your implementation

Nc                 4   > [         TU ]  " S0 UD6  0 U l        g N )super__init___params)selfkwargs	__class__s     J/var/www/html/env/lib/python3.13/site-packages/matplotlib/layout_engine.pyr   LayoutEngine.__init__>   s    "6"    c                     [         e)z+
Set the parameters for the layout engine.
NotImplementedError)r   r   s     r   setLayoutEngine.setB   s
     "!r   c                 @    U R                   c  [        eU R                   $ )zK
Return a boolean if the layout engine creates colorbars using a
gridspec.
)_colorbar_gridspecr   r   s    r   colorbar_gridspecLayoutEngine.colorbar_gridspecH   "     ""*%%&&&r   c                 @    U R                   c  [        eU R                   $ )zV
Return a boolean if the layout engine is compatible with
`~.Figure.subplots_adjust`.
)_adjust_compatibler   r   s    r   adjust_compatibleLayoutEngine.adjust_compatibleR   r    r   c                 ,    [        U R                  5      $ )z6
Return copy of the parameters for the layout engine.
)dictr   r   s    r   getLayoutEngine.get\   s     DLL!!r   c                     [         e)z2
Execute the layout on the figure given by *fig*.
r   r   figs     r   executeLayoutEngine.executeb   s
    
 "!r   )r   )__name__
__module____qualname____firstlineno____doc__r"   r   r   r   propertyr   r#   r'   r,   __static_attributes____classcell__r   s   @r   r   r      sW    > " ' ' ' '"" "r   r   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )PlaceHolderLayoutEnginej   a  
This layout engine does not adjust the figure layout at all.

The purpose of this `.LayoutEngine` is to act as a placeholder when the user removes
a layout engine to ensure an incompatible `.LayoutEngine` cannot be set later.

Parameters
----------
adjust_compatible, colorbar_gridspec : bool
    Allow the PlaceHolderLayoutEngine to mirror the behavior of whatever
    layout engine it is replacing.

c                 >   > Xl         X l        [        TU ]  " S0 UD6  g r   )r"   r   r   r   )r   r#   r   r   r   s       r   r    PlaceHolderLayoutEngine.__init__x   s    "3"3"6"r   c                     g)z
Do nothing.
Nr   r*   s     r   r,   PlaceHolderLayoutEngine.execute}   s     	r   )r"   r   )	r.   r/   r0   r1   r2   r   r,   r4   r5   r6   s   @r   r8   r8   j   s    #
 r   r8   c                   \   ^  \ rS rSrSrSrSrSSSSS.U 4S jjrS	 rSSSSS
.S jr	Sr
U =r$ )TightLayoutEngine   zb
Implements the ``tight_layout`` geometry management.  See
:ref:`tight_layout_guide` for details.
TgHzG?Nr   r      rB   padh_padw_padrectc                v   > [         TU ]  " S0 UD6  S H  nSU R                  U'   M     U R                  XX4S9  g)a  
Initialize tight_layout engine.

Parameters
----------
pad : float, default: 1.08
    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: (0, 0, 1, 1).
    rectangle in normalized figure coordinates that the subplots
    (including labels) will fit into.
rC   Nr   )r   r   r   r   )r   rD   rE   rF   rG   r   tdr   s          r   r   TightLayoutEngine.__init__   s?    " 	"6"3B#DLL 4 	SU>r   c                 @   U R                   nUR                  5       n[        US[        5      " 5          [	        XR
                  [        UR
                  5      UUS   US   US   US   S9nSSS5        W(       a  UR                  " S0 UD6  gg! , (       d  f       N)= f)	a  
Execute tight_layout.

This decides the subplot parameters given the padding that
will allow the Axes labels to not be covered by other labels
and Axes.

Parameters
----------
fig : `.Figure` to perform layout on.

See Also
--------
.figure.Figure.tight_layout
.pyplot.tight_layout
_draw_disabledrD   rE   rF   rG   rC   Nr   )r   _get_renderergetattrr   r   axesr   subplots_adjust)r   r+   inforendererr   s        r   r,   TightLayoutEngine.execute   s    " ||$$&X/=?,XX3CHH=xKtG}DM&\#F @
 )&)  @?s   9B
B)rD   rF   rE   rG   c                    U R                   R                   H-  n[        5       U   c  M  [        5       U   U R                  U'   M/     g)a  
Set the pads for tight_layout.

Parameters
----------
pad : float
    Padding between the figure edge and the edges of subplots, as a
    fraction of the font size.
w_pad, h_pad : float
    Padding (width/height) between edges of adjacent subplots.
    Defaults to *pad*.
rect : tuple (left, bottom, right, top)
    rectangle in normalized figure coordinates that the subplots
    (including labels) will fit into.
Nr   __kwdefaults__localsr   )r   rD   rF   rE   rG   rI   s         r   r   TightLayoutEngine.set   s8      (())Bx|'#)8B<R  *r   r   r.   r/   r0   r1   r2   r"   r   r   r,   r   r4   r5   r6   s   @r   r?   r?      sD     "$d"? ?.*6 TD 0 0r   r?   c                   b   ^  \ rS rSrSrSrSrSSSSSSS.U 4S jjrS rSSSSSS	.S
 jr	Sr
U =r$ )ConstrainedLayoutEngine   zm
Implements the ``constrained_layout`` geometry management.  See
:ref:`constrainedlayout_guide` for details.
FNrA   )rE   rF   hspacewspacerG   compressc                  > [         TU ]  " S0 UD6  U R                  [        R                  S   [        R                  S   [        R                  S   [        R                  S   SS9  U R                  X!XCUS9  X`l        g)	a  
Initialize ``constrained_layout`` settings.

Parameters
----------
h_pad, w_pad : float
    Padding around the Axes elements in inches.
    Default to :rc:`figure.constrained_layout.h_pad` and
    :rc:`figure.constrained_layout.w_pad`.
hspace, wspace : float
    Fraction of the figure to dedicate to space between the
    axes.  These are evenly spread between the gaps between the Axes.
    A value of 0.2 for a three-column layout would have a space
    of 0.1 of the figure width between each column.
    If h/wspace < h/w_pad, then the pads are used instead.
    Default to :rc:`figure.constrained_layout.hspace` and
    :rc:`figure.constrained_layout.wspace`.
rect : tuple of 4 floats
    Rectangle in figure coordinates to perform constrained layout in
    (left, bottom, width, height), each from 0-1.
compress : bool
    Whether to shift Axes so that white space in between them is
    removed. This is useful for simple grids of fixed-aspect Axes (e.g.
    a grid of images).  See :ref:`compressed_layout`.
zfigure.constrained_layout.w_padzfigure.constrained_layout.h_padz figure.constrained_layout.wspacez figure.constrained_layout.hspacerA   )rF   rE   r^   r]   rG   Nr   )r   r   r   mplrcParams	_compress)	r   rE   rF   r]   r^   rG   r_   r   r   s	           r   r    ConstrainedLayoutEngine.__init__   s{    8 	"6"s||$EF||$EF%GH%GH"	 	 	$ 	u& 	 	!r   c           
          UR                  5       u  p#U R                  S   U-  nU R                  S   U-  n[        XUU R                  S   U R                  S   U R                  S   U R                  S9$ )z
Perform constrained_layout and move and resize Axes accordingly.

Parameters
----------
fig : `.Figure` to perform layout on.
rF   rE   r^   r]   rG   )rF   rE   r^   r]   rG   r_   )get_size_inchesr   r   rc   )r   r+   widthheightrF   rE   s         r   r,   ConstrainedLayoutEngine.execute  sv     ++-W%-W%.$SU,0LL,B,0LL,B*.,,v*>.2nn	> 	>r   )rE   rF   r]   r^   rG   c                    U R                   R                   H-  n[        5       U   c  M  [        5       U   U R                  U'   M/     g)a$  
Set the pads for constrained_layout.

Parameters
----------
h_pad, w_pad : float
    Padding around the Axes elements in inches.
    Default to :rc:`figure.constrained_layout.h_pad` and
    :rc:`figure.constrained_layout.w_pad`.
hspace, wspace : float
    Fraction of the figure to dedicate to space between the
    axes.  These are evenly spread between the gaps between the Axes.
    A value of 0.2 for a three-column layout would have a space
    of 0.1 of the figure width between each column.
    If h/wspace < h/w_pad, then the pads are used instead.
    Default to :rc:`figure.constrained_layout.hspace` and
    :rc:`figure.constrained_layout.wspace`.
rect : tuple of 4 floats
    Rectangle in figure coordinates to perform constrained layout in
    (left, bottom, width, height), each from 0-1.
NrU   )r   rE   rF   r]   r^   rG   rI   s          r   r   ConstrainedLayoutEngine.set  s8    . (())Bx|'#)8B<R  *r   )rc   rY   r6   s   @r   r[   r[      sM    
  $DT&" &"P>&  t40 0r   r[   )r2   
contextlibr   
matplotlibra   matplotlib._constrained_layoutr   matplotlib._tight_layoutr   r   r   r8   r?   r[   r   r   r   <module>rp      sP   " #  @?L" L"^l 4L0 L0^]0l ]0r   