o
    id                     @   s   d 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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)cbook)SubplotBase)SubplotSpecGridSpec   )	axes_sizec                   @   s   e Zd ZdZ	d4ddZdd Zdd	 Z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d5d!d"Zd#d$ Zd%d& Zd'd( Zd)d* Zd6d+d,Zd7d-d.Zd/d0 Zd8d2d3ZdS )9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/edux/Edux_v2/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>8       z0Divider.get_horizontal_sizes.<locals>.<listcomp>)get_horizontalr   r%   r   r$   r   get_horizontal_sizes7      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_sizesc                 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)        r4   r4   r   )l
total_sizers_sumas_sum_rs_askr   r   r   _calc_kB   s   
zDivider._calc_kc                 C   s2   dg}| D ]\}}| |d ||  |  q|S Nr4   )append)r5   r;   offsetsr9   r:   r   r   r   _calc_offsetsQ   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_positionX   s   
	zDivider.set_positionc                 C      | j S )z%Return the position of the rectangle.rC   r   r   r   r   get_positionc      zDivider.get_positionc                 C   s(   t |dkrtjtjj|d || _dS )a  
        Parameters
        ----------
        anchor : {'C', 'SW', 'S', 'SE', 'E', 'NE', 'N', 'NW', 'W'}
            anchor position

          =====  ============
          value  description
          =====  ============
          'C'    Center
          'SW'   bottom left
          'S'    bottom
          'SE'   bottom right
          'E'    right
          'NE'   top right
          'N'    top
          'NW'   top left
          'W'    left
          =====  ============

           )r   N)lenr   _check_in_listmtransformsBboxcoefsr   )r   r   r   r   r   
set_anchorg   s   
zDivider.set_anchorc                 C   rE   )zReturn the anchor.)r   rF   r   r   r   
get_anchor   rH   zDivider.get_anchorc                 C   rB   )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   rE   )zReturn horizontal sizes.rQ   rF   r   r   r   r(      rH   zDivider.get_horizontalc                 C   rB   )z
        Parameters
        ----------
        v : list of :mod:`~mpl_toolkits.axes_grid1.axes_size`
            sizes for vertical division
        Nr   )r   vr   r   r   set_vertical   rT   zDivider.set_verticalc                 C   rE   )zReturn vertical sizes.rU   rF   r   r   r   r,      rH   zDivider.get_verticalFc                 C   rB   )zE
        Parameters
        ----------
        aspect : bool
        Nr   r   r   r   r   r   
set_aspect   s   
zDivider.set_aspectc                 C   rE   )zReturn aspect.rX   rF   r   r   r   
get_aspect   rH   zDivider.get_aspectc                 C   s
   || _ d S r.   r   )r   r   r   r   r   set_locator   s   
zDivider.set_locatorc                 C   rE   r.   r\   rF   r   r   r   get_locator   s   zDivider.get_locatorc                 C   s    | j d u r	|  S |  ||jS r.   )r   rG   bounds)r   axr%   r   r   r   get_position_runtime   s   
zDivider.get_position_runtimec                 C   s  | j  \}}| ||\}	}
}}| |}| |}| ||| }| ||| }|  rvt||}| ||}| ||}|d |d  | }|d |d  | }t	j
|	|
||}t	j
|	|
||}||  |}|j|j}}n| ||}| ||}|	|
}}|du r|d }|du r|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   )r
   get_size_inchesra   r*   r-   r<   r[   minrA   rL   rM   from_boundsanchoredrP   x0y0)r   nxnynx1ny1axesr%   figWfigHxywrR   hsizesvsizesk_hk_vr;   oxoywwhhpbpb1pb1_anchoredrf   rg   x1w1y1h1r   r   r   locate   s4   



&&zDivider.locatec                 C   s   t | ||||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.
        AxesLocator)r   rh   ri   rj   rk   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   rK   )r   r   sizer   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helperr   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-   r3   staticmethodr<   rA   rD   rG   rO   rP   rS   r(   rW   r,   rZ   r[   r]   r^   ra   r   r   r   r   r   r   r   r   r      s8    


		


2r   c                   @   s*   e Zd ZdZd	ddZdd Zdd ZdS )
r   z|
    A simple callable object, initialized with AxesDivider class,
    returns the position and size of the given cell.
    Nc                 C   s`   || _ |j}|j}|| || | _| _|du r|d }|du r$|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   )_axes_dividerr   r   _nx_ny_nx1_ny1)r   axes_dividerrh   ri   rj   rk   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   rl   r%   r   r   r   r   r   __call__4  s   zAxesLocator.__call__c                 C      t | jdr| j S d S Nget_subplotspec)hasattrr   r   rF   r   r   r   r   @     
zAxesLocator.get_subplotspecr   )r   r   r   r   r   r   r   r   r   r   r   r     s
    
r   c                   @   sT   e Zd ZdZdddddddZdd Zd	d
 Zdd Zdd Zdd Z	dd Z
dS )SubplotDividerT
    The Divider class whose rectangle area is specified as a subplot geometry.
    Nr	   )r   r   r   r   c             	   G   sD   || _ t||| _|   tj| || jj|pg |pg ||d 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)	figurer   _from_subplot_args_subplotspecupdate_paramsr   r   figboxr_   )r   r   r   r   r   r   argsr   r   r   r   L  s   
zSubplotDivider.__init__c                 C   s   |    | jjS )z%Return the bounds of the subplot box.)r   r   r_   rF   r   r   r   rG   d  s   zSubplotDivider.get_positionc                 C   s   |   | j| _dS )z1Update the subplot position from fig.subplotpars.N)r   rG   r   r   rF   r   r   r   r   i  s   zSubplotDivider.update_paramsc                 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   m  s   zSubplotDivider.get_geometryc                 C   s,   t |||d  | _|   | | j dS )z;Change subplot geometry, e.g., from (1, 1, 1) to (2, 2, 3).r   N)r   r   r   rD   r   )r   numrowsnumcolsnumr   r   r   change_geometrys  s   zSubplotDivider.change_geometryc                 C   rE   )zGet the SubplotSpec instance.r   rF   r   r   r   r   y  rH   zSubplotDivider.get_subplotspecc                 C   rB   )zSet the SubplotSpec instance.Nr   )r   subplotspecr   r   r   set_subplotspec}  s   
zSubplotDivider.set_subplotspec)r   r   r   r   r   rG   r   r   r   r   r   r   r   r   r   r   G  s    r   c                   @   sf   e Zd ZdZdddZddddZdd	d
ZdddZdddZdd Z	dd Z
dd Zdd ZdS )AxesDividerz1
    Divider based on the pre-existing axes.
    Nc              	   C   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   rl   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   rG   )r   r   kwargsrl   r   r   r   _get_new_axes  s   
zAxesDivider._get_new_axesFc                 K   s   |du rt jddd |r2t|tjstj|| jd}|r,| jd| |  j	d7  _	n| j
| t|tjs@tj|| jd}|rY| jd| |  j	d7  _	| jd| jd}n| j
| | jt| jd | jd}| jd	i |}|| |S )
a  
        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
            A width of the axes. If float or string is given, *from_any*
            function is used to create the size, with *ref_size* set to AxesX
            instance of the current axes.
        pad : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
            Pad between the axes. It takes same argument as *size*.
        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.
        N3.2zrIn a future version, 'pad' will default to rcParams['figure.subplot.wspace'].  Set pad=0 to keep the old behavior.messagefraction_refr   r   rh   ri   r   )r   warn_deprecatedr   r/   _Basefrom_anyr   r   r   r   r?   r   r   rJ   r   set_axes_locatorr   r   r   
pack_startr   locatorr`   r   r   r   new_horizontal  0   
zAxesDivider.new_horizontalc                 K   s   |du rt jddd |r2t|tjstj|| jd}|r,| jd| |  j	d7  _	n| j
| t|tjs@tj|| jd}|rY| jd| |  j	d7  _	| j| jdd}n| j
| | j| jt| jd d}| jd	i |}|| |S )
a  
        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
            A height of the axes. If float or string is given, *from_any*
            function is used to create the size, with *ref_size* set to AxesX
            instance of the current axes.
        pad : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
            Pad between the axes. It takes same argument as *size*.
        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.
        Nr   zrIn a future version, 'pad' will default to rcParams['figure.subplot.hspace'].  Set pad=0 to keep the old behavior.r   r   r   r   r   r   )r   r   r   r/   r   r   r   r   r   r   r?   r   r   rJ   r   r   r   r   r   r   new_vertical  r   zAxesDivider.new_verticalTc                 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   rK   r
   add_axes)r   r   r   r   add_to_figurer   r`   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[   rY   r   r   r   r[   #  s   

zAxesDivider.get_aspectc                 C   s$   | j d u r| jjdd}|jS | j S r   )r   r   rG   r_   )r   bboxr   r   r   rG   -  s   
zAxesDivider.get_positionc                 C   s   | j d u r
| j S | j S r.   )r   r   rP   rF   r   r   r   rP   4  s   

zAxesDivider.get_anchorc                 C   r   r   )r   r   r   rF   r   r   r   r   :  r   zAxesDivider.get_subplotspecr   )NF)NT)r   r   r   r   r   r   r   r   r   r[   rG   rP   r   r   r   r   r   r     s    



1
1
r   c                   @   s@   e Zd Zedd Zedd ZdddZdd	 Zdd
dZdS )HBoxDividerc                 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>   )	rJ   npasarrayTzerosfill_diagonalsumlinalgsolve)equivalent_sizesappended_sizesmax_equivalent_sizetotal_appended_sizeneq_rseq_asap_rsap_asABkarray_HkarrayHr   r   r   _determine_karrayC  s    zHBoxDivider._determine_karrayc                 C   s<   dg}t | |D ]\\}}}||d ||  |  q|S r=   )zipr?   )r   r   r@   rar;   r   r   r   rA   [  s   zHBoxDivider._calc_offsetsNc                 C   s   t | |d|dS )a	  
        Create a new `~mpl_toolkits.axes_grid.axes_divider.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.
        r   Nr   )r   rh   rj   r   r   r   r   b  s   zHBoxDivider.new_locatorc	                 C   s   |}	|}
|| }|| }|  |	|
||}| |
|}|d |d  | }|	d }|d |d  |d  | }tj||||}tj||||}||  |}|j|j}}||||fS )Nr>   r   r   )	r   rA   rL   rM   rd   re   rP   rf   rg   )r   ro   rp   rq   rR   y_equivalent_sizesx_appended_sizesrm   rn   r   r   r   r   r   rv   rx   ref_hry   rz   r{   r|   rf   rg   r   r   r   _locates  s"   zHBoxDivider._locatec              
   C   s   | j  \}}| ||\}	}
}}| |}| |}| |	|
||||||\}}}}|du r3|d }||| |  || ||  | }}||}}tj||||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.
        axes
        renderer
        Nr   )	r
   rb   ra   r-   r*   r  rL   rM   rd   )r   rh   ri   rj   rk   rl   r%   rm   rn   ro   rp   rq   rR   r  r  rf   rg   rv   ry   r}   r~   r   r   r   r   r   r     s   

&
zHBoxDivider.locater.   r   )	r   r   r   r   r   rA   r   r  r   r   r   r   r   r   A  s    


r   c                   @   s$   e Zd ZdZdddZdddZdS )	VBoxDividerr   Nc                 C   s   t | d|d|S )a  
        Create a new `~mpl_toolkits.axes_grid.axes_divider.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   Nr   )r   ri   rk   r   r   r   r     s   zVBoxDivider.new_locatorc              
   C   s   | j  \}}| ||\}	}
}}| |}| |}| |
|	||||||\}}}}|du r3|d }||}}||| |  || ||  | }}tj||||S r  )	r
   rb   ra   r*   r-   r  rL   rM   rd   )r   rh   ri   rj   rk   rl   r%   rm   rn   ro   rp   rq   rR   x_equivalent_sizesy_appended_sizesrg   rf   rw   rx   r}   r~   r   r   r   r   r   r     s   


&zVBoxDivider.locater.   r   )r   r   r   r   r   r   r   r   r   r   r    s    
r  c                 C   s$   t | }|jddd}| | |S )Nr   r   )r   r   r   )rl   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   )r`   r   r   r   r
  r   r   r   make_axes_area_auto_adjustable  s   
r  )Nr   N)r   numpyr   
matplotlibr   matplotlib.axesr   matplotlib.gridspecr   r   matplotlib.transforms
transformsrL    r   r/   r   r   r   r   r   r  r  r  r   r   r   r   <module>   s(      4; @k6	