o
    tBhg                     @   s   d Z ddlZddlZddlmZ ddlmZ ddlm	Z	m
Z
 ddlmZ ddlmZ G dd	 d	ZG d
d dZG dd deZG dd deZdd Zdd 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)SubplotBase)SubplotSpecGridSpec   )	axes_sizec                   @   s   e Zd ZdZ	d5ddZdd Zdd	 Zed
dd Z	e
dd Ze
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d6d"d#Zd$d% Zd&d' Zd(d) Zd*d+ Zd7d,d-Zd8d.d/Zd0d1 Zd9d3d4ZdS ):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   s:   || _ || _|| _|| _|| _|| _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
            Whether overall rectangular area is reduced so that the relative
            part of the horizontal and vertical scales have the same scale.
        anchor : {'C', 'SW', 'S', 'SE', 'E', 'NE', 'N', 'NW', 'W'}
            Placement of the reduced rectangle, when *aspect* is True.
        r   N)	_fig_pos_horizontal	_vertical_anchor_aspect
_xrefindex
_yrefindex_locator)selffigpos
horizontalverticalaspectanchor r   {/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/mpl_toolkits/axes_grid1/axes_divider.py__init__   s   
zDivider.__init__c                        fdd|   D S )Nc                       g | ]}|  qS r   get_size.0srendererr   r   
<listcomp>9       z0Divider.get_horizontal_sizes.<locals>.<listcomp>)get_horizontalr   r%   r   r$   r   get_horizontal_sizes8      zDivider.get_horizontal_sizesc                    r   )Nc                    r   r   r   r!   r$   r   r   r&   <   r'   z.Divider.get_vertical_sizes.<locals>.<listcomp>)get_verticalr)   r   r$   r   get_vertical_sizes;   r+   zDivider.get_vertical_sizes3.5c                 C   s$   t |  }t |  }||fS N)SizeAddListr,   r(   )r   vsizehsizer   r   r   get_vsize_hsize>   s   zDivider.get_vsize_hsizec                 C   sB   d\}}| D ]\}}||7 }||7 }q|dkr|| | }|S dS )N)        r5   r5   r   )l
total_sizers_sumas_sum_rs_askr   r   r   _calc_kD   s   
zDivider._calc_kc                 C   s2   dg}| D ]\}}| |d ||  |  q|S Nr5   )append)r6   r<   offsetsr:   r;   r   r   r   _calc_offsetsS   s   zDivider._calc_offsetsc                 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_positionZ   s   
	zDivider.set_positionc                 C      | j S )z%Return the position of the rectangle.rD   r   r   r   r   get_positione      zDivider.get_positionc                 C   s(   t |dkrtjtjj|d || _dS )a  
        Parameters
        ----------
        anchor : (float, float) or {'C', 'SW', 'S', 'SE', 'E', 'NE', ...}
            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   N)lenr   check_in_listmtransformsBboxcoefsr   )r   r   r   r   r   
set_anchori   s   
zDivider.set_anchorc                 C   rF   )zReturn the anchor.)r   rG   r   r   r   
get_anchorz   rI   zDivider.get_anchorc                 C   rC   )z
        Parameters
        ----------
        h : list of :mod:`~mpl_toolkits.axes_grid1.axes_size`
            sizes for horizontal division
        Nr   )r   hr   r   r   set_horizontal~      
zDivider.set_horizontalc                 C   rF   )zReturn horizontal sizes.rR   rG   r   r   r   r(      rI   zDivider.get_horizontalc                 C   rC   )z
        Parameters
        ----------
        v : list of :mod:`~mpl_toolkits.axes_grid1.axes_size`
            sizes for vertical division
        Nr   )r   vr   r   r   set_vertical   rU   zDivider.set_verticalc                 C   rF   )zReturn vertical sizes.rV   rG   r   r   r   r,      rI   zDivider.get_verticalFc                 C   rC   )zE
        Parameters
        ----------
        aspect : bool
        Nr   r   r   r   r   r   
set_aspect   s   
zDivider.set_aspectc                 C   rF   )zReturn aspect.rY   rG   r   r   r   
get_aspect   rI   zDivider.get_aspectc                 C   s
   || _ d S r/   r   )r   r   r   r   r   set_locator   s   
zDivider.set_locatorc                 C   rF   r/   r]   rG   r   r   r   get_locator   s   zDivider.get_locatorc                 C   s    | j d u r	|  S |  ||jS r/   )r   rH   bounds)r   axr%   r   r   r   get_position_runtime   s   
zDivider.get_position_runtimec                 C   s  | j jj| j j \}}| ||\}	}
}}| |}| |}| ||| }| ||| }|  rzt	||}| 
||}| 
||}|d |d  | }|d |d  | }tj|	|
||}tj|	|
||}||  |}|j|j}}n| 
||}| 
||}|	|
}}|du rtjddd |d }|du rtjddd |d }||| |  || ||  | }}||| |  || ||  | }}tj||||S )	a  
        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.
        axes
        renderer
        r?   r   Nr.   Support for passing nx1=None to mean nx+1 is deprecated since %(since)s; in a future version, nx1=None will mean 'up to the last cell'.messager   Support for passing ny1=None to mean ny+1 is deprecated since %(since)s; in a future version, ny1=None will mean 'up to the last cell'.)r
   bboxsizedpirb   r*   r-   r=   r\   minrB   rM   rN   from_boundsanchoredrQ   x0y0r   warn_deprecated)r   nxnynx1ny1axesr%   fig_wfig_hxywrS   hsizesvsizesk_hk_vr<   oxoywwhhpbpb1pb1_anchoredrm   rn   x1w1y1h1r   r   r   locate   s@   



&&zDivider.locatec                 C   s2   t | |||dur
|n|d |dur|S |d S )a  
        Return a new `AxesLocator` 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   AxesLocator)r   rp   rq   rr   rs   r   r   r   new_locator   s   
zDivider.new_locatorc                 C   s   |dkr| j d| |  jd7  _d S |dkr | j | d S |dkr4| jd| |  jd7  _d S |dkr@| j| d S tjg d|d d S )	Nleftr   r   rightbottomtopr   r   r   r   position)r   insertr   r@   r   r   r   rL   )r   r   rh   r   r   r   append_size   s   

zDivider.append_size皙?c                 C   sZ   |d u rg d}ddl m}m}m} |D ]}|||}||}	||	|}
| ||
 qd S )Nr   r   )PaddedSizeFromFuncGetExtentHelper)r   r   r   r   r   )r   use_axespadadjust_dirsr   r   r   dhelperrh   padded_sizer   r   r   add_auto_adjustable_area  s   

z Divider.add_auto_adjustable_area)Nr	   )FNNNNNN)r   N)__name__
__module____qualname____doc__r   r*   r-   r   
deprecatedr4   staticmethodr=   rB   rE   rH   rP   rQ   rT   r(   rX   r,   r[   r\   r^   r_   rb   r   r   r   r   r   r   r   r   r      s:    



		


:r   c                   @   s*   e Zd ZdZd	ddZdd Zdd ZdS )
r   z`
    A callable object which returns the position and size of a given
    AxesDivider cell.
    Nc                 C   s|   || _ |j}|j}|| || | _| _|du r#tjddd |d }|du r2tjddd |d }|| | _|| | _dS )a  
        Parameters
        ----------
        axes_divider : AxesDivider
        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.   rc   rd   r   rf   )	_axes_dividerr   r   _nx_nyr   ro   _nx1_ny1)r   axes_dividerrp   rq   rr   rs   r   r   r   r   r   r     s    
zAxesLocator.__init__c                 C   s>   | j j}| j j}| j | j| | j| | j| | j| ||S r/   )r   r   r   r   r   r   r   r   )r   rt   r%   r   r   r   r   r   __call__A  s   zAxesLocator.__call__c                 C      t | jdr| j S d S Nget_subplotspec)hasattrr   r   rG   r   r   r   r   M     
zAxesLocator.get_subplotspecr   )r   r   r   r   r   r   r   r   r   r   r   r     s
    
$r   c                       s   e Zd ZdZddddd fdd
Zdd Zed	ed
d Z	ed	dd Z
ejd	ddddd Zejd	dd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)).
        )r   r   r   r   r   N)figuresuperr   set_subplotspecr   _from_subplot_args)r   r   r   r   r   r   args	__class__r   r   r   Y  s   zSubplotDivider.__init__c                 C   s   |   | jjS )z%Return the bounds of the subplot box.)r   rH   r   r`   rG   r   r   r   rH   p  s   zSubplotDivider.get_positionz3.4c                 C   s   |   | jS r/   )r   rH   r   rG   r   r   r   figboxt  s   zSubplotDivider.figboxc                 C   s   d S r/   r   rG   r   r   r   update_paramsy  s   zSubplotDivider.update_paramsr   z1(get_subplotspec returns a SubplotSpec instance.))alternativeaddendumc                 C   s"   |    \}}}}|||d fS )z*Get the subplot geometry, e.g., (2, 2, 3).r   )r   get_geometry)r   rowscolsnum1num2r   r   r   r   }  s   zSubplotDivider.get_geometryr   r   c                 C   s,   t |||d  | _|   | | j dS )z;Change subplot geometry, e.g., from (1, 1, 1) to (2, 2, 3).r   N)r   _subplotspecr   rE   r   )r   numrowsnumcolsnumr   r   r   change_geometry  s   zSubplotDivider.change_geometryc                 C   rF   )zGet the SubplotSpec instance.)r   rG   r   r   r   r     rI   zSubplotDivider.get_subplotspecc                 C   s   || _ | || j dS )zSet the SubplotSpec instance.N)r   rE   rH   r   )r   subplotspecr   r   r   r     s   zSubplotDivider.set_subplotspec)r   r   r   r   r   rH   r   r   propertyr   r   r   r   r   r   __classcell__r   r   r   r   r   T  s(    


r   c                       s~   e Zd ZdZd fdd	ZddddZdd	d
ZdddZej	dddddddZ
dd Zdd Zdd Zdd Z  ZS )AxesDividerz1
    Divider based on the pre-existing 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   )	_axesr0   AxesX_xrefAxesY_yrefr   r   
get_figure)r   rt   xrefyrefr   r   r   r     s   
zAxesDivider.__init__)
axes_classc                K   sF   | j }|d u rt|tr|j}nt|}|| |jddfi |S NT)original)r   
isinstancer   _axes_classtyper   rH   )r   r   kwargsrt   r   r   r   _get_new_axes  s   
zAxesDivider._get_new_axesFc                 K   s   |du rt jd | j }|r3t|tjstj|| jd}|r-| jd| |  j	d7  _	n| j
| t|tjsAtj|| jd}|rZ| jd| |  j	d7  _	| jd| jd}n| j
| | jt| jd | jd}| jdi |}|| |S )ak  
        Add a new axes on the right (or left) side of the main axes.

        Parameters
        ----------
        size : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
            The axes width.  float or str arguments are interpreted as
            ``axes_size.from_any(size, AxesX(<main_axes>))``.
        pad : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
            Padding between the axes.  float or str arguments are interpreted
            as ``axes_size.from_any(size, AxesX(<main_axes>))``.  Defaults to
            :rc:`figure.subplot.wspace` times the main axes width.
        pack_start : bool
            If False, the new axes is appended at the end
            of the list, i.e., it became the right-most axes. If True, it is
            inserted at the start of the list, and becomes the left-most axes.
        **kwargs
            All extra keywords arguments are passed to the created axes.
            If *axes_class* is given, the new axes will be created as an
            instance of the given class. Otherwise, the same class of the
            main axes will be used.
        Nzfigure.subplot.wspacefraction_refr   r   rp   rq   r   )mplrcParamsr   r   r0   _Basefrom_anyr   r   r   r@   r   r   rK   r   set_axes_locatorr   rh   r   
pack_startr   locatorra   r   r   r   new_horizontal  ,   
zAxesDivider.new_horizontalc                 K   s   |du rt jd | j }|r3t|tjstj|| jd}|r-| jd| |  j	d7  _	n| j
| t|tjsAtj|| jd}|rZ| jd| |  j	d7  _	| j| jdd}n| j
| | j| jt| jd d}| jdi |}|| |S )am  
        Add a new axes on the top (or bottom) side of the main axes.

        Parameters
        ----------
        size : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
            The axes height.  float or str arguments are interpreted as
            ``axes_size.from_any(size, AxesY(<main_axes>))``.
        pad : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
            Padding between the axes.  float or str arguments are interpreted
            as ``axes_size.from_any(size, AxesY(<main_axes>))``.  Defaults to
            :rc:`figure.subplot.hspace` times the main axes height.
        pack_start : bool
            If False, the new axes is appended at the end
            of the list, i.e., it became the right-most axes. If True, it is
            inserted at the start of the list, and becomes the left-most axes.
        **kwargs
            All extra keywords arguments are passed to the created axes.
            If *axes_class* is given, the new axes will be created as an
            instance of the given class. Otherwise, the same class of the
            main axes will be used.
        Nzfigure.subplot.hspacer   r   r   r   r   )r   r   r   r   r0   r   r   r   r   r   r@   r   r   rK   r   r   r   r   r   r   new_vertical  r   zAxesDivider.new_verticalr.   add_to_figurezax.remove()r   Tc                 K   s   |dkr| j ||fddi|}n<|dkr"| j ||fddi|}n+|dkr3| j||fddi|}n|dkrD| j||fddi|}n	tjg d|d	 |rU| j| |S )
z
        Create an axes at the given *position* with the same height
        (or width) of the main axes.

         *position*
           ["left"|"right"|"bottom"|"top"]

         *size* and *pad* should be axes_grid.axes_size compatible.
        r   r   Tr   Fr   r   r   r   )r   r   r   rL   r
   add_axes)r   r   rh   r   r   r   ra   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   r\   rZ   r   r   r   r\   4  s   

zAxesDivider.get_aspectc                 C   s$   | j d u r| jjdd}|jS | j S r   )r   r   rH   r`   )r   rg   r   r   r   rH   >  s   
zAxesDivider.get_positionc                 C   s   | j d u r
| j S | j S r/   )r   r   rQ   rG   r   r   r   rQ   E  s   

zAxesDivider.get_anchorc                 C   r   r   )r   r   r   rG   r   r   r   r   K  r   zAxesDivider.get_subplotspecr   )NF)NT)r   r   r   r   r   r   r   r   r   delete_parameterr   r\   rH   rQ   r   r   r   r   r   r   r     s    


//
r   c                 C   s   t |}t|j\}}t| j\}}t|d |d f}	t|d }
t|	d |d |f | d|	d |df< ||	dd df< | |
d |< |t| |
d< tj|	|
}|d d }|d }||krn|| | }|S )Nr   r?   )	rK   npasarrayTzerosfill_diagonalsumlinalgsolve)summed_widthsequal_heightstotal_width
max_heightneq_rseq_assm_rssm_asABkarray_and_heightkarrayheightr   r   r   _determine_karrayU  s    r
  c                 C   s<   dg}t | |D ]\\}}}||d ||  |  q|S r>   )zipr@   )summed_sizesr  rA   rar<   r   r   r   rB   m  s   rB   c	                 C   s   t |||| || d}	t||	}
|
d |
d  | }|d \}}|	d | | | }tj| |||}tj| |||}|||}|j|j}}|||
|fS )N)r   r   r?   r   )r
  rB   rM   rN   rk   rl   rm   rn   )rw   rx   ry   rS   r   r   ru   rv   r   r  r~   r   h0_rh0_ar   r   r   r   rm   rn   r   r   r   _locateu  s   
r  c                   @   $   e Zd ZdZdddZdddZd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                 C   s$   t | |d|dur|dS |d dS )a  
        Create a new `AxesLocator` 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   Nr   r   )r   rp   rr   r   r   r   r     s   $zHBoxDivider.new_locatorc                 C   s   | j jj| j j \}}| ||\}	}
}}| |}| |}t|	|
|||||||  	\}}}}|d u r@t	j
ddd |d }||| |  || ||  | }}||}}tj||||S )Nr.   rc   rd   r   )r
   rg   rh   ri   rb   r*   r-   r  rQ   r   ro   rM   rN   rk   )r   rp   rq   rr   rs   rt   r%   ru   rv   rw   rx   ry   rS   	summed_wsequal_hsrm   rn   r~   r   r   r   r   r   r   r   r   r     s   

&
zHBoxDivider.locater/   r   r   r   r   r   r   r   r   r   r   r   r    s    
	r  c                   @   r  )	VBoxDividerzl
    A `SubplotDivider` for laying out axes vertically, while ensuring that they
    have equal widths.
    Nc                 C   s"   t | d|d|dur|S |d S )a  
        Create a new `AxesLocator` 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   Nr   )r   rq   rs   r   r   r   r     s   "zVBoxDivider.new_locatorc                 C   s   | j jj| j j \}}| ||\}	}
}}| |}| |}t|
|	|||||||  	\}}}}|d u r@t	j
ddd |d }||}}||| |  || ||  | }}tj||||S )Nr.   rf   rd   r   )r
   rg   rh   ri   rb   r-   r*   r  rQ   r   ro   rM   rN   rk   )r   rp   rq   rr   rs   rt   r%   ru   rv   rw   rx   ry   rS   	summed_hsequal_wsrn   rm   r   r   r   r   r   r   r   r   r   r     s   


&zVBoxDivider.locater/   r   r  r   r   r   r   r    s    
r  c                 C   s$   t | }|jddd}| | |S )Nr   r   )r   r   r   )rt   dividerr   r   r   r   make_axes_locatable  s   
r  r   c                 C   s8   |d u rg d}t | }|d u r| }|j|||d d S )Nr   )r   r   r   )r  r   )ra   r   r   r   r  r   r   r   make_axes_area_auto_adjustable  s   
r  )Nr   N)r   numpyr   
matplotlibr   r   matplotlib.axesr   matplotlib.gridspecr   r   matplotlib.transforms
transformsrM    r   r0   r   r   r   r   r
  rB   r  r  r  r  r  r   r   r   r   <module>   s0      
=B @+'	