rL i,dZddlmZddlZddlmZddlmZm Z GddZ Gdd e Z Gd d e Z Gd d e Z y)a 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 has two built-in layout engines: - `.TightLayoutEngine` was the first layout engine added to Matplotlib. See also :ref:`tight_layout_guide`. - `.ConstrainedLayoutEngine` is more modern and generally gives better results. See also :ref:`constrainedlayout_guide`. Third parties can create their own layout engine by subclassing `.LayoutEngine`. ) nullcontextN)do_constrained_layout)get_subplotspec_listget_tight_layout_figurec\eZdZdZdZdZfdZdZedZ edZ dZ dZ xZ S) LayoutEnginea 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 2t|di|i|_yN)super__init___params)selfkwargs __class__s ^/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/matplotlib/layout_engine.pyr zLayoutEngine.__init__Cs "6" c t)z; Set the parameters for the layout engine. NotImplementedError)rrs rsetzLayoutEngine.setGs "!rc>|jt|jS)zc Return a boolean if the layout engine creates colorbars using a gridspec. )_colorbar_gridspecrrs rcolorbar_gridspeczLayoutEngine.colorbar_gridspecM"  " " *% %&&&rc>|jt|jS)zn Return a boolean if the layout engine is compatible with `~.Figure.subplots_adjust`. )_adjust_compatiblerrs radjust_compatiblezLayoutEngine.adjust_compatibleWrrc,t|jS)zF Return copy of the parameters for the layout engine. )dictrrs rgetzLayoutEngine.getasDLL!!rct)zB Execute the layout on the figure given by *fig*. rrfigs rexecutezLayoutEngine.executegs "!r)__name__ __module__ __qualname____doc__rrr rpropertyrrr"r& __classcell__rs@rrr sR>" ''''" "rrc(eZdZdZfdZdZxZS)PlaceHolderLayoutEnginea 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 @||_||_t| di|yr )rrr r )rrrrrs rr z PlaceHolderLayoutEngine.__init__}s#"3"3 "6"rcy)z Do nothing. Nr r$s rr&zPlaceHolderLayoutEngine.executes r)r'r(r)r*r r&r,r-s@rr/r/os # rr/cNeZdZdZdZdZdddddfd ZdZddddd d ZxZ S) TightLayoutEnginezn Implements the ``tight_layout`` geometry management. See :ref:`tight_layout_guide` for details. TgHzG?Nrrr5padh_padw_padrectc zt|di|dD]}d|j|<|j||||y)a0 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. r6Nr )r r rr)rr7r8r9r:rtdrs rr zTightLayoutEngine.__init__sH" "6"3 $B#DLL  $ SU>rc 4|j}|j}t|dt5t ||j t |j ||d|d|d|d}dddr|jdi|yy#1swYxYw) 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_disabledr7r8r9r:r6Nr )r _get_renderergetattrrraxesrsubplots_adjust)rr%inforendererrs rr&zTightLayoutEngine.executes"||$$& =WX/ = ? #,SXX3CHH=xKtG}DM&\#F #  C   )& )   # #s =BB)r7r9r8r:c|jjD]*}t|t||j|<,y)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. Nr__kwdefaults__localsr)rr7r9r8r:r<s rrzTightLayoutEngine.sets= (()) 0Bx|'#)8B< R  0r r'r(r)r*rrr r&rr,r-s@rr3r3s?"$d"?.*6TD00rr3cTeZdZdZdZdZdddddddfd ZdZddddddd ZxZ S) ConstrainedLayoutEnginezy Implements the ``constrained_layout`` geometry management. See :ref:`constrainedlayout_guide` for details. FNr4)r8r9hspacewspacer:compressc t|di||jtjdtjdtjdtjdd|j|||||||_y) 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`. zfigure.constrained_layout.w_padzfigure.constrained_layout.h_padz figure.constrained_layout.wspacez figure.constrained_layout.hspacer4)r9r8rMrLr:Nr )r r rmplrcParams _compress) rr8r9rLrMr:rNrrs rr z ConstrainedLayoutEngine.__init__s8 "6" s||$EF||$EF %GH %GH"  $ uE&  !rc |j\}}|jd|z }|jd|z }t||||jd|jd|jd|jS)z Perform constrained_layout and move and resize Axes accordingly. Parameters ---------- fig : `.Figure` to perform layout on. r9r8rMrLr:)r9r8rMrLr:rN)get_size_inchesrrrR)rr%widthheightr9r8s rr&zConstrainedLayoutEngine.execute sz++- v W%- W%.$SU,0LL,B,0LL,B*.,,v*>.2nn > >r)r8r9rLrMr:c|jjD]*}t|t||j|<,y)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. NrF)rr8r9rLrMr:r<s rrzConstrainedLayoutEngine.sets=.(()) 0Bx|'#)8B< R  0rrIr-s@rrKrKsH  $DT &"P>& t400rrK)r* contextlibr matplotlibrPmatplotlib._constrained_layoutrmatplotlib._tight_layoutrrrr/r3rKr rrr\sP,#@?L"L"^l4L0 L0^]0l]0r