o
    -hU                     @   s   d Z ddlZddlZddlZddlmZ ddlmZ ddl	m
Z ddlmZ G dd dZG d	d
 d
eZG dd deZdd ZG dd deZG dd deZdd Z	dddZdS )zJ
Helper classes to adjust the positions of multiple axes at drawing time.
    N)_api)SubplotSpec   )	axes_sizec                   @   s   e Zd ZdZ	d4ddZdd Zdd	 Zd
d Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zd5ddZdd  Zd!d" Zd#d$ Zd%d& Zed'd( Zed)d* Zd6d+d,Zd-d. Zd/d0 Zd7d2d3ZdS )8DivideraQ  
    An Axes positioning class.

    The divider is initialized with lists of horizontal and vertical sizes
    (:mod:`mpl_toolkits.axes_grid1.axes_size`) based on which a given
    rectangular area will be divided.

    The `new_locator` method then creates a callable object
    that can be used as the *axes_locator* of the axes.
    NCc                 C   sD   || _ || _|| _|| _|| _| | || _d| _d| _d| _	dS )a  
        Parameters
        ----------
        fig : Figure
        pos : tuple of 4 floats
            Position of the rectangle that will be divided.
        horizontal : list of :mod:`~mpl_toolkits.axes_grid1.axes_size`
            Sizes for horizontal division.
        vertical : list of :mod:`~mpl_toolkits.axes_grid1.axes_size`
            Sizes for vertical division.
        aspect : bool, optional
            Whether overall rectangular area is reduced so that the relative
            part of the horizontal and vertical scales have the same scale.
        anchor : (float, float) or {'C', 'SW', 'S', 'SE', 'E', 'NE', 'N', 'NW', 'W'}, default: 'C'
            Placement of the reduced rectangle, when *aspect* is True.
        r   N)
_fig_pos_horizontal	_vertical_anchor
set_anchor_aspect
_xrefindex
_yrefindex_locator)selffigpos
horizontalverticalaspectanchor r   X/var/www/vscode/kcb/lib/python3.10/site-packages/mpl_toolkits/axes_grid1/axes_divider.py__init__   s   

zDivider.__init__c                       t  fdd|  D S )Nc                       g | ]}|  qS r   get_size.0srendererr   r   
<listcomp><       z0Divider.get_horizontal_sizes.<locals>.<listcomp>)nparrayget_horizontalr   r$   r   r#   r   get_horizontal_sizes;      zDivider.get_horizontal_sizesc                    r   )Nc                    r   r   r   r    r#   r   r   r%   ?   r&   z.Divider.get_vertical_sizes.<locals>.<listcomp>)r'   r(   get_verticalr*   r   r#   r   get_vertical_sizes>   r,   zDivider.get_vertical_sizesc                 C   
   || _ dS )z
        Set the position of the rectangle.

        Parameters
        ----------
        pos : tuple of 4 floats
            position of the rectangle that will be divided
        Nr	   )r   r   r   r   r   set_positionA   s   
	zDivider.set_positionc                 C      | j S )z%Return the position of the rectangle.r0   r   r   r   r   get_positionL      zDivider.get_positionc                 C   sJ   t |trtjtjj|d nt |ttfrt	|dkr t
d|| _dS )a  
        Parameters
        ----------
        anchor : (float, float) or {'C', 'SW', 'S', 'SE', 'E', 'NE', 'N', 'NW', 'W'}
            Either an (*x*, *y*) pair of relative coordinates (0 is left or
            bottom, 1 is right or top), 'C' (center), or a cardinal direction
            ('SW', southwest, is bottom left, etc.).

        See Also
        --------
        .Axes.set_anchor
        )r      zanchor must be str or 2-tupleN)
isinstancestrr   check_in_listmtransformsBboxcoefstuplelistlen	TypeErrorr   )r   r   r   r   r   r   P   s
   

zDivider.set_anchorc                 C   r2   )zReturn the anchor.)r   r3   r   r   r   
get_anchord   r5   zDivider.get_anchorc                 C   s   d S Nr   r3   r   r   r   get_subplotspech   s   zDivider.get_subplotspecc                 C   r/   )z
        Parameters
        ----------
        h : list of :mod:`~mpl_toolkits.axes_grid1.axes_size`
            sizes for horizontal division
        Nr
   )r   hr   r   r   set_horizontalk      
zDivider.set_horizontalc                 C   r2   )zReturn horizontal sizes.rD   r3   r   r   r   r)   t   r5   zDivider.get_horizontalc                 C   r/   )z
        Parameters
        ----------
        v : list of :mod:`~mpl_toolkits.axes_grid1.axes_size`
            sizes for vertical division
        Nr   )r   vr   r   r   set_verticalx   rG   zDivider.set_verticalc                 C   r2   )zReturn vertical sizes.rH   r3   r   r   r   r-      r5   zDivider.get_verticalFc                 C   r/   )zE
        Parameters
        ----------
        aspect : bool
        Nr   r   r   r   r   r   
set_aspect   s   
zDivider.set_aspectc                 C   r2   )zReturn aspect.rK   r3   r   r   r   
get_aspect   r5   zDivider.get_aspectc                 C   s
   || _ d S rB   r   )r   r   r   r   r   set_locator      
zDivider.set_locatorc                 C   r2   rB   rO   r3   r   r   r   get_locator   s   zDivider.get_locatorc                 C   s    | j d u r	|  S |  ||jS rB   )r   r4   bounds)r   axr$   r   r   r   get_position_runtime   s   
zDivider.get_position_runtimec                 C   s"   |  d\}}|r|| | S dS )Nr   )sum)sizestotalrel_sumabs_sumr   r   r   _calc_k   s   zDivider._calc_kc                 C   s   t dg| |dg S )Nr   r   )r'   cumsum)rW   kr   r   r   _calc_offsets   s   zDivider._calc_offsetsc                 C   s\   |du r|d }|du r|d }| j }| j}t| j|| || || || }| j|_|S )a  
        Return an axes locator callable for the specified cell.

        Parameters
        ----------
        nx, nx1 : int
            Integers specifying the column-position of the
            cell. When *nx1* is None, a single *nx*-th column is
            specified. Otherwise, location of columns spanning between *nx*
            to *nx1* (but excluding *nx1*-th column) is specified.
        ny, ny1 : int
            Same as *nx* and *nx1*, but for row positions.
        Nr   )r   r   	functoolspartial_locaterC   )r   nxnynx1ny1xrefyreflocatorr   r   r   new_locator   s   zDivider.new_locatorc                 C   s  || j 7 }|| j 7 }|| j7 }|| j7 }| jjj| jj \}}| ||\}	}
}}| |}| |}| 	||| }| 	||| }| 
 rt||}| ||}| ||}|d |d  | }|d |d  | }tj|	|
||}tj|	|
||}||  |j\}}n| ||}| ||}|	|
}}|du rd}|du rd}||| |  || ||  | }}||| |  || ||  | }}tj||||S )a  
        Implementation of ``divider.new_locator().__call__``.

        The axes locator callable returned by ``new_locator()`` is created as
        a `functools.partial` of this method with *nx*, *ny*, *nx1*, and *ny1*
        specifying the requested cell.
        r   N)r   r   r   bboxsizedpirU   r+   r.   r[   rN   minr^   r:   r;   from_boundsanchoredrA   p0)r   rb   rc   rd   re   axesr$   fig_wfig_hxywrE   hsizesvsizesk_hk_vr]   oxoywwhhpbpb1x0y0x1w1y1h1r   r   r   ra      s:   







&&zDivider._locatec                 C   s   t jg d|d |dkr| jd| |  jd7  _d S |dkr)| j| d S |dkr=| jd| |  jd7  _d S | j| d S )Nleftrightbottomtoppositionr   r   r   r   r   )r   r9   r
   insertr   appendr   r   )r   r   rl   r   r   r   append_size   s   
zDivider.append_size皙?c                 C   s6   |du rg d}|D ]}|  |t|||  q
dS )a5  
        Add auto-adjustable padding around *use_axes* to take their decorations
        (title, labels, ticks, ticklabels) into account during layout.

        Parameters
        ----------
        use_axes : `~matplotlib.axes.Axes` or list of `~matplotlib.axes.Axes`
            The Axes whose decorations are taken into account.
        pad : float, default: 0.1
            Additional padding in inches.
        adjust_dirs : list of {"left", "right", "bottom", "top"}, optional
            The sides where padding is added; defaults to all four sides.
        Nr   )r   Size_AxesDecorationsSize)r   use_axespadadjust_dirsdr   r   r   add_auto_adjustable_area  s
   z Divider.add_auto_adjustable_area)Nr   )FNN)r   N)__name__
__module____qualname____doc__r   r+   r.   r1   r4   r   rA   rC   rF   r)   rJ   r-   rM   rN   rP   rR   rU   staticmethodr[   r^   ri   ra   r   r   r   r   r   r   r      s8    
		



 /r   c                       sD   e Zd ZdZddddd fdd
Zdd Zd	d
 Zdd Z  ZS )SubplotDividerzT
    The Divider class whose rectangle area is specified as a subplot geometry.
    Nr   r   r   r   r   c                   s@   || _ t j|g d|pg |pg ||d | t|| dS )a  
        Parameters
        ----------
        fig : `~matplotlib.figure.Figure`

        *args : tuple (*nrows*, *ncols*, *index*) or int
            The array of subplots in the figure has dimensions ``(nrows,
            ncols)``, and *index* is the index of the subplot being created.
            *index* starts at 1 in the upper left corner and increases to the
            right.

            If *nrows*, *ncols*, and *index* are all single digit numbers, then
            *args* can be passed as a single 3-digit number (e.g. 234 for
            (2, 3, 4)).
        horizontal : list of :mod:`~mpl_toolkits.axes_grid1.axes_size`, optional
            Sizes for horizontal division.
        vertical : list of :mod:`~mpl_toolkits.axes_grid1.axes_size`, optional
            Sizes for vertical division.
        aspect : bool, optional
            Whether overall rectangular area is reduced so that the relative
            part of the horizontal and vertical scales have the same scale.
        anchor : (float, float) or {'C', 'SW', 'S', 'SE', 'E', 'NE', 'N', 'NW', 'W'}, default: 'C'
            Placement of the reduced rectangle, when *aspect* is True.
        )r   r   r   r   r   N)figuresuperr   set_subplotspecr   _from_subplot_args)r   r   r   r   r   r   args	__class__r   r   r      s   zSubplotDivider.__init__c                 C   s   |   | jjS )z%Return the bounds of the subplot box.)rC   r4   r   rS   r3   r   r   r   r4   A  s   zSubplotDivider.get_positionc                 C   r2   )zGet the SubplotSpec instance.)_subplotspecr3   r   r   r   rC   E  r5   zSubplotDivider.get_subplotspecc                 C   s   || _ | || j dS )zSet the SubplotSpec instance.N)r   r1   r4   r   )r   subplotspecr   r   r   r   I  s   zSubplotDivider.set_subplotspec)	r   r   r   r   r   r4   rC   r   __classcell__r   r   r   r   r     s    !r   c                       st   e Zd ZdZd fdd	ZddddZdd	d
ZdddZdddddZdd Z	dd Z
dd Zdd Z  ZS )AxesDividerz0
    Divider based on the preexisting axes.
    Nc                    sf   || _ |du rt|| _n|| _|du rt|| _n|| _t j| d| jg| jgddd dS )zw
        Parameters
        ----------
        axes : :class:`~matplotlib.axes.Axes`
        xref
        yref
        Nr   )r   r   r   r   r   r   )	_axesr   AxesX_xrefAxesY_yrefr   r   
get_figure)r   rr   rf   rg   r   r   r   r   T  s   
zAxesDivider.__init__)
axes_classc                K   s4   | j }|d u rt|}|| |jddfi |S NT)original)r   typer   r4   )r   r   kwargsrr   r   r   r   _get_new_axesj  s   zAxesDivider._get_new_axesFc                 K   s   |du rt jd | j }|rdnd}|r(t|tjs"tj|| jd}| || t|tjs6tj|| jd}| || | j|rBdnt	| j
d | jd}| jd	i |}|| |S )
z
        Helper method for ``append_axes("left")`` and ``append_axes("right")``.

        See the documentation of `append_axes` for more details.

        :meta private:
        Nzfigure.subplot.wspacer   r   fraction_refr   r   rb   rc   r   )mplrcParamsr   r7   r   _Basefrom_anyr   ri   r?   r
   r   r   set_axes_locatorr   rl   r   
pack_startr   r   rh   rT   r   r   r   new_horizontalq  s"   
zAxesDivider.new_horizontalc                 K   s   |du rt jd | j }|rdnd}|r(t|tjs"tj|| jd}| || t|tjs6tj|| jd}| || | j| j	|rDdnt
| jd d}| jd	i |}|| |S )
z
        Helper method for ``append_axes("top")`` and ``append_axes("bottom")``.

        See the documentation of `append_axes` for more details.

        :meta private:
        Nzfigure.subplot.hspacer   r   r   r   r   r   r   )r   r   r   r7   r   r   r   r   ri   r   r?   r   r   r   r   r   r   r   new_vertical  s"   
zAxesDivider.new_verticalc          	      K   s\   t j| jdf| jdf| jdf| jdfd|d\}}|||f||d|}| j| |S )am  
        Add a new axes on a given side of the main axes.

        Parameters
        ----------
        position : {"left", "right", "bottom", "top"}
            Where the new axes is positioned relative to the main axes.
        size : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
            The axes width or height.  float or str arguments are interpreted
            as ``axes_size.from_any(size, AxesX(<main_axes>))`` for left or
            right axes, and likewise with ``AxesY`` for bottom or top axes.
        pad : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
            Padding between the axes.  float or str arguments are interpreted
            as for *size*.  Defaults to :rc:`figure.subplot.wspace` times the
            main Axes width (left or right axes) or :rc:`figure.subplot.hspace`
            times the main Axes height (bottom or top axes).
        axes_class : subclass type of `~.axes.Axes`, optional
            The type of the new axes.  Defaults to the type of the main axes.
        **kwargs
            All extra keywords arguments are passed to the created axes.
        TFr   r   )r   r   )r   check_getitemr   r   r   add_axes)	r   r   rl   r   r   r   create_axesr   rT   r   r   r   append_axes  s"   
zAxesDivider.append_axesc                 C   s*   | j d u r| j }|dkrdS dS | j S )NautoFT)r   r   rN   rL   r   r   r   rN     s   

zAxesDivider.get_aspectc                 C   s$   | j d u r| jjdd}|jS | j S r   )r	   r   r4   rS   )r   rk   r   r   r   r4     s   
zAxesDivider.get_positionc                 C   s   | j d u r
| j S | j S rB   )r   r   rA   r3   r   r   r   rA     s   

zAxesDivider.get_anchorc                 C   s
   | j  S rB   )r   rC   r3   r   r   r   rC     rQ   zAxesDivider.get_subplotspecr   )NFrB   )r   r   r   r   r   r   r   r   r   rN   r4   rA   rC   r   r   r   r   r   r   O  s    

"
r   c	                 C   s*  || }	|| }
t |}|j\}}|j\}}tg |d}d|d |df< ||dd df< g | |	|  }tj||^ }}||
krN|
| | }tdg|| | }|d |d  | }|d \}}|d | | | }tj	
| |||}tj	
| |||}|||j\}}||||fS )Nr   rj   )r?   Tr'   diagrV   linalgsolver\   r:   r;   ro   rp   rq   )ru   rv   rw   rE   summed_widthsequal_heightsrs   rt   r   total_width
max_heightneq_relseq_absssm_relssm_abssABkarrayheightr|   r~   h0_relh0_absr   r   r   r   r   r   r   r   ra     s(   

ra   c                       *   e Zd ZdZd fdd	Zdd Z  ZS )HBoxDividerz
    A `.SubplotDivider` for laying out axes horizontally, while ensuring that
    they have equal heights.

    Examples
    --------
    .. plot:: gallery/axes_grid1/demo_axes_hbox_divider.py
    Nc                    s   t  |d|dS )a  
        Create an axes locator callable for the specified cell.

        Parameters
        ----------
        nx, nx1 : int
            Integers specifying the column-position of the
            cell. When *nx1* is None, a single *nx*-th column is
            specified. Otherwise, location of columns spanning between *nx*
            to *nx1* (but excluding *nx1*-th column) is specified.
        r   r   ri   )r   rb   rd   r   r   r   ri        zHBoxDivider.new_locatorc                 C   s   || j 7 }|| j 7 }| jjj| jj \}}| ||\}	}
}}| |}| |}t|	|
||||||| 	 	\}}}}|d u rAd}||| |  || ||  | }}||}}t
j||||S Nrj   )r   r   rk   rl   rm   rU   r+   r.   ra   rA   r:   r;   ro   )r   rb   rc   rd   re   rr   r$   rs   rt   ru   rv   rw   rE   	summed_wsequal_hsr   r   r|   r   r   r   r   r   r   r   r   ra     s   



&
zHBoxDivider._locaterB   r   r   r   r   ri   ra   r   r   r   r   r   r     s    	r   c                       r   )VBoxDividerzm
    A `.SubplotDivider` for laying out axes vertically, while ensuring that
    they have equal widths.
    Nc                    s   t  d|d|S )a  
        Create an axes locator callable for the specified cell.

        Parameters
        ----------
        ny, ny1 : int
            Integers specifying the row-position of the
            cell. When *ny1* is None, a single *ny*-th row is
            specified. Otherwise, location of rows spanning between *ny*
            to *ny1* (but excluding *ny1*-th row) is specified.
        r   r   )r   rc   re   r   r   r   ri   3  r   zVBoxDivider.new_locatorc                 C   s   || j 7 }|| j 7 }| jjj| jj \}}| ||\}	}
}}| |}| |}t|
|	||||||| 	 	\}}}}|d u rAd}||}}||| |  || ||  | }}t
j||||S r   )r   r   rk   rl   rm   rU   r.   r+   ra   rA   r:   r;   ro   )r   rb   rc   rd   re   rr   r$   rs   rt   ru   rv   rw   rE   	summed_hsequal_wsr   r   r}   r~   r   r   r   r   r   r   r   ra   A  s   




&zVBoxDivider._locaterB   r   r   r   r   r   r   -  s    r   c                 C   s$   t | }|jddd}| | |S )Nr   r   )r   ri   r   )rr   dividerrh   r   r   r   make_axes_locatableR  s   
r   r   c                 C   s8   |du rg d}t | }|du r| }|j|||d dS )aG  
    Add auto-adjustable padding around *ax* to take its decorations (title,
    labels, ticks, ticklabels) into account during layout, using
    `.Divider.add_auto_adjustable_area`.

    By default, padding is determined from the decorations of *ax*.
    Pass *use_axes* to consider the decorations of other Axes instead.
    Nr   )r   r   r   )r   r   )rT   r   r   r   r   r   r   r   make_axes_area_auto_adjustableZ  s   

r   )Nr   N)r   r_   numpyr'   
matplotlibr   r   matplotlib.gridspecr   matplotlib.transforms
transformsr:    r   r   r   r   r   ra   r   r   r   r   r   r   r   r   <module>   s(      4 !)%	