o
    jU                     @   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   e/var/www/html/Deteccion_Ine/venv/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BboxZ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.rC   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   rF   zDivider.set_verticalc                 C   r2   )zReturn vertical sizes.rG   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.rJ   r3   r   r   r   
get_aspect   r5   zDivider.get_aspectc                 C   s
   || _ d S rA   r   )r   r   r   r   r   set_locator      
zDivider.set_locatorc                 C   r2   rA   rN   r3   r   r   r   get_locator   s   zDivider.get_locatorc                 C   s    | j d u r	|  S |  ||jS rA   )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totalZrel_sumZabs_sumr   r   r   _calc_k   s   zDivider._calc_kc                 C   s   t dg| |dg S )Nr   r   )r'   cumsum)rV   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_locaterB   )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dpirT   r+   r.   rX   rM   minr[   r:   r;   from_boundsanchoredr@   p0)r   r_   r`   ra   rb   axesr$   fig_wfig_hxywrD   ZhsizesZvsizesZk_hZk_vrZ   oxoywwhhpbpb1x0y0x1w1y1h1r   r   r   r^      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   ri   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   SizeZ_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   r@   rB   rE   r)   rI   r-   rL   rM   rO   rQ   rT   staticmethodrX   r[   rf   r^   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   Z_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.)rB   r4   r   rR   r3   r   r   r   r4   A  s   zSubplotDivider.get_positionc                 C   r2   )zGet the SubplotSpec instance.)_subplotspecr3   r   r   r   rB   E  r5   zSubplotDivider.get_subplotspecc                 C   s   || _ | || j dS )zSet the SubplotSpec instance.N)r   r1   r4   r   )r   Zsubplotspecr   r   r   r   I  s   zSubplotDivider.set_subplotspec)	r   r   r   r   r   r4   rB   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   ZAxesX_xrefZAxesY_yrefr   r   
get_figure)r   ro   rc   rd   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   kwargsro   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   Zfraction_refr   r   r_   r`   r   )mplrcParamsr   r7   r   _Basefrom_anyr   rf   r>   r
   r   r   set_axes_locatorr   ri   r   
pack_startr   r   re   rS   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   rf   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   Zcheck_getitemr   r   r   Zadd_axes)	r   r   ri   r   r   r   Zcreate_axesr   rS   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   rM   rK   r   r   r   rM     s   

zAxesDivider.get_aspectc                 C   s$   | j d u r| jjdd}|jS | j S r   )r	   r   r4   rR   )r   rh   r   r   r   r4     s   
zAxesDivider.get_positionc                 C   s   | j d u r
| j S | j S rA   )r   r   r@   r3   r   r   r   r@     s   

zAxesDivider.get_anchorc                 C   s
   | j  S rA   )r   rB   r3   r   r   r   rB     rP   zAxesDivider.get_subplotspecr   )NFrA   )r   r   r   r   r   r   r   r   r   rM   r4   r@   rB   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   rg   )r>   Tr'   ZdiagrU   ZlinalgZsolverY   r:   r;   rl   rm   rn   )rr   rs   rt   rD   Zsummed_widthsZequal_heightsrp   rq   r   total_width
max_heightnZeq_relsZeq_abssZsm_relsZsm_abssABZkarrayheightru   rw   Zh0_relZh0_absrx   ry   rz   r{   r|   r   r   r   r^     s(   

r^   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   rf   )r   r_   ra   r   r   r   rf        zHBoxDivider.new_locatorc                 C   s   || j 7 }|| j 7 }| jjj| jj \}}| ||\}	}
}}| |}| |}t|	|
||||||| 	 	\}}}}|d u rAd}||| |  || ||  | }}||}}t
j||||S Nrg   )r   r   rh   ri   rj   rT   r+   r.   r^   r@   r:   r;   rl   )r   r_   r`   ra   rb   ro   r$   rp   rq   rr   rs   rt   rD   Z	summed_wsZequal_hsr{   r|   ru   rx   r}   r~   r   r   r   r   r   r^     s   



&
zHBoxDivider._locaterA   r   r   r   r   rf   r^   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   r`   rb   r   r   r   rf   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   rh   ri   rj   rT   r.   r+   r^   r@   r:   r;   rl   )r   r_   r`   ra   rb   ro   r$   rp   rq   rr   rs   rt   rD   Z	summed_hsZequal_wsr|   r{   rv   rw   r}   r~   r   r   r   r   r   r^   A  s   




&zVBoxDivider._locaterA   r   r   r   r   r   r   -  s    r   c                 C   s$   t | }|jddd}| | |S )Nr   r   )r   rf   r   )ro   dividerre   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   )rS   r   r   r   r   r   r   r   make_axes_area_auto_adjustableZ  s   

r   )Nr   N)r   r\   numpyr'   Z
matplotlibr   r   Zmatplotlib.gridspecr   Zmatplotlib.transformsZ
transformsr:    r   r   r   r   r   r^   r   r   r   r   r   r   r   r   <module>   s(      4 !)%	