U
    ÂmœdÉX  ã                   @   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
 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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d2d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d3dd„Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zed%d&„ ƒZed'd(„ ƒZd4d)d*„Zd5d+d,„Zd-d.„ Zd6d0d1„ZdS )7Ú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
            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'}
            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   ú]/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/mpl_toolkits/axes_grid1/axes_divider.pyÚ__init__   s    
zDivider.__init__c                    s   t  ‡ fdd„|  ¡ D ƒ¡S )Nc                    s   g | ]}|  ˆ ¡‘qS r   ©Úget_size©Ú.0Ús©Úrendererr   r   Ú
<listcomp>:   s     z0Divider.get_horizontal_sizes.<locals>.<listcomp>)ÚnpÚarrayÚget_horizontal©r   r"   r   r!   r   Úget_horizontal_sizes9   s    zDivider.get_horizontal_sizesc                    s   t  ‡ fdd„|  ¡ D ƒ¡S )Nc                    s   g | ]}|  ˆ ¡‘qS r   r   r   r!   r   r   r#   =   s     z.Divider.get_vertical_sizes.<locals>.<listcomp>)r$   r%   Úget_verticalr'   r   r!   r   Úget_vertical_sizes<   s    zDivider.get_vertical_sizesc                 C   s
   || _ 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_position?   s    	zDivider.set_positionc                 C   s   | j S )z%Return the position of the rectangle.r+   ©r   r   r   r   Úget_positionJ   s    zDivider.get_positionc                 C   sJ   t |tƒrtjtjj|d� n"t |ttfƒr8t	|ƒ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   N   s
    
zDivider.set_anchorc                 C   s   | j S )zReturn the anchor.)r   r-   r   r   r   Ú
get_anchorb   s    zDivider.get_anchorc                 C   s
   || _ dS )z—
        Parameters
        ----------
        h : list of :mod:`~mpl_toolkits.axes_grid1.axes_size`
            sizes for horizontal division
        N©r
   )r   Úhr   r   r   Úset_horizontalf   s    zDivider.set_horizontalc                 C   s   | j S )zReturn horizontal sizes.r:   r-   r   r   r   r&   o   s    zDivider.get_horizontalc                 C   s
   || _ dS )z•
        Parameters
        ----------
        v : list of :mod:`~mpl_toolkits.axes_grid1.axes_size`
            sizes for vertical division
        N©r   )r   Úvr   r   r   Úset_verticals   s    zDivider.set_verticalc                 C   s   | j S )zReturn vertical sizes.r=   r-   r   r   r   r)   |   s    zDivider.get_verticalFc                 C   s
   || _ dS )zE
        Parameters
        ----------
        aspect : bool
        N©r   ©r   r   r   r   r   Ú
set_aspect€   s    zDivider.set_aspectc                 C   s   | j S )zReturn aspect.r@   r-   r   r   r   Ú
get_aspectˆ   s    zDivider.get_aspectc                 C   s
   || _ d S ©N©r   )r   r   r   r   r   Úset_locatorŒ   s    zDivider.set_locatorc                 C   s   | j S rD   rE   r-   r   r   r   Úget_locator�   s    zDivider.get_locatorc                 C   s$   | j d kr|  ¡ S |   ||¡jS d S rD   )r   r.   Ú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| |dg •¡S )Nr   r   )r   )r$   Úcumsum)rL   Úkr   r   r   Ú_calc_offsetsŸ   s    zDivider._calc_offsetsc                 C   sˆ  | j jj| j j \}}|  ||¡\}	}
}}|  |¡}|  |¡}|  ||| ¡}|  ||| ¡}|  ¡ rìt	||ƒ}|  
||¡}|  
||¡}|d |d  | }|d |d  | }tj |	|
||¡}tj |	|
||¡}| |  ¡ |¡j\}}n"|  
||¡}|  
||¡}|	|
 }}|dk�rd}|dk�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, the
            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   N)r   ÚbboxÚsizeÚdpirJ   r(   r*   rN   rC   ÚminrQ   r3   r4   Úfrom_boundsÚanchoredr9   Úp0)r   ÚnxÚnyÚnx1Úny1Úaxesr"   Úfig_wÚfig_hÚxÚyÚwr;   ZhsizesZvsizesZk_hZk_vrP   ÚoxÚoyÚwwÚhhÚpbÚpb1Úx0Úy0Úx1Úw1Úy1Úh1r   r   r   Úlocate¥   s2    





&&zDivider.locatec                 C   s0   t | |||dk	r|n|d |dk	r&|n|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   rZ   r[   r\   r]   r   r   r   Únew_locatorÖ   s      ýzDivider.new_locatorc                 C   sˆ   t jddddg|d� |dkr<| j d|¡ |  jd7  _nH|dkrR| j |¡ n2|dkrx| j d|¡ |  jd7  _n| j |¡ d S )NÚleftÚrightÚbottomÚtop©Úpositionr   r   )r   r2   r
   Úinsertr   Úappendr   r   )r   ry   rT   r   r   r   Úappend_sizeé   s    ÿzDivider.append_sizeçš™™™™™¹?c                 C   s:   |dkrddddg}|D ]}|   |t ||¡| ¡ qdS )a1  
        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, optional
            Additional padding in inches.
        adjust_dirs : list of {"left", "right", "bottom", "top"}, optional
            The sides where padding is added; defaults to all four sides.
        Nrt   ru   rv   rw   )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)NNNN)NN)r}   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r(   r*   r,   r.   r   r9   r<   r&   r?   r)   rB   rC   rF   rG   rJ   ÚstaticmethodrN   rQ   rp   rs   r|   rƒ   r   r   r   r   r      s6      ÿ
		



1
r   c                   @   s*   e Zd ZdZd	dd„Zdd„ Zdd„ ZdS )
rr   zc
    A callable object which returns the position and size of a given
    `.AxesDivider` cell.
    Nc                 C   sh   || _ |j}|j}|| ||  | _| _|dkr:t| j ƒ}|dkrPt| j d ƒ}|| | _|| | _dS )aì  
        Parameters
        ----------
        axes_divider : `~mpl_toolkits.axes_grid1.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Ú_nyr7   Ú_nx1Ú_ny1)r   Zaxes_dividerrZ   r[   r\   r]   r   r   r   r   r   r     s    

zAxesLocator.__init__c                 C   s>   | j j}| j j}| j  | j| | j| | j| | j| ||¡S rD   )r‰   r   r   rp   rŠ   r‹   rŒ   r�   )r   r^   r"   r   r   r   r   r   Ú__call__-  s    ûzAxesLocator.__call__c                 C   s
   | j  ¡ S rD   )r‰   Úget_subplotspecr-   r   r   r   r�   9  s    zAxesLocator.get_subplotspec)NN)r„   r…   r†   r‡   r   rŽ   r�   r   r   r   r   rr     s   
rr   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                   sD   || _ tƒ j|ddddg|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‘   N)ÚfigureÚsuperr   Úset_subplotspecr   Z_from_subplot_args)r   r   r   r   r   r   Úargs©Ú	__class__r   r   r   B  s      þzSubplotDivider.__init__c                 C   s   |   ¡  | j¡jS )z%Return the bounds of the subplot box.)r�   r.   r’   rH   r-   r   r   r   r.   Y  s    zSubplotDivider.get_positionc                 C   s   | j S )zGet the SubplotSpec instance.)Ú_subplotspecr-   r   r   r   r�   ]  s    zSubplotDivider.get_subplotspecc                 C   s   || _ |  | | j¡¡ dS )zSet the SubplotSpec instance.N)r˜   r,   r.   r’   )r   Zsubplotspecr   r   r   r”   a  s    zSubplotDivider.set_subplotspec)	r„   r…   r†   r‡   r   r.   r�   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krt |¡| _n|| _|dkr8t |¡| _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   r^   ZxrefZyrefr–   r   r   r   l  s      þzAxesDivider.__init__)Ú
axes_classc                K   s0   | j }|d krt|ƒ}|| ¡ |jdd�f|ŽS ©NT)Úoriginal)r›   Útyperž   r.   )r   rŸ   Úkwargsr^   r   r   r   Ú_get_new_axes‚  s    ÿzAxesDivider._get_new_axesFc                 K   sô   |dkrt jd | j }|rft|tjƒs8tj|| jd�}|rZ| j d|¡ |  j	d7  _	n| j 
|¡ t|tjƒs‚tj|| jd�}|r´| j d|¡ |  j	d7  _	| jd| jd�}n&| j 
|¡ | jt| jƒd | jd�}| jf |Ž}| |¡ |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.wspace©Zfraction_refr   r   ©rZ   r[   )ÚmplÚrcParamsrœ   r0   r~   Ú_BaseÚfrom_anyr
   rz   r   r{   rs   r   r7   r¤   Úset_axes_locator©r   rT   r€   Ú
pack_startr£   ÚlocatorrI   r   r   r   Únew_horizontal‰  s.     ÿ
zAxesDivider.new_horizontalc                 K   sô   |dkrt jd | j }|rft|tjƒs8tj|| jd�}|rZ| j d|¡ |  j	d7  _	n| j 
|¡ t|tjƒs‚tj|| jd�}|r´| j d|¡ |  j	d7  _	| j| jdd�}n&| j 
|¡ | j| jt| jƒd d�}| jf |Ž}| |¡ |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�   r0   r~   r©   rª   r   rz   r   r{   rs   r   r7   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.
        TF)rt   ru   rv   rw   rx   )r­   rŸ   )r   Zcheck_getitemr¯   r°   r   Zadd_axes)	r   ry   rT   r€   rŸ   r£   Zcreate_axesr­   rI   r   r   r   Úappend_axesÉ  s&    üû
 ÿ ÿÿzAxesDivider.append_axesc                 C   s0   | j d kr&| j ¡ }|dkr dS dS n| j S d S )NÚautoFT)r   r›   rC   rA   r   r   r   rC   ë  s    

zAxesDivider.get_aspectc                 C   s(   | j d kr| jjdd�}|jS | j S d S r    )r	   r›   r.   rH   )r   rS   r   r   r   r.   õ  s    
zAxesDivider.get_positionc                 C   s   | j d kr| j ¡ S | j S d S rD   )r   r›   r9   r-   r   r   r   r9   ü  s    

zAxesDivider.get_anchorc                 C   s
   | j  ¡ S rD   )r›   r�   r-   r   r   r   r�     s    zAxesDivider.get_subplotspec)NN)NF)NF)N)r„   r…   r†   r‡   r   r¤   r¯   r°   r±   rC   r.   r9   r�   r™   r   r   r–   r   rš   g  s   
 
 "
rš   c	                 C   s"  || }	|| }
t |ƒ}|j\}}|j\}}t |d•¡}d|d |…df< ||dd d…f< | |	| ¡  f•}tj ||¡�^ }}||
kr–|
| | }t d|| | •¡}|d |d  | }|d \}}|d | | | }tj	 
| |||¡}tj	 
| |||¡}| ||¡j\}}||||fS )Nr   rR   )r   )r   )r7   ÚTr$   ZdiagrK   ZlinalgZsolverO   r3   r4   rW   rX   rY   )ra   rb   rc   r;   Zsummed_widthsZequal_heightsr_   r`   r   Útotal_widthÚ
max_heightÚnZeq_relsZeq_abssZsm_relsZsm_abssÚAÚBZkarrayÚheightrd   rf   Zh0_relZh0_absrg   rh   ri   rj   rk   r   r   r   Ú_locate	  s(    

rº   c                   @   s$   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k	r|n|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   rq   )r   rZ   r\   r   r   r   rs   4  s    zHBoxDivider.new_locatorc                 C   s°   | j jj| j j \}}|  ||¡\}	}
}}|  |¡}|  |¡}t|	|
|||||||  ¡ ƒ	\}}}}|d krnd}||| |  || ||  |  }}|| }}t	j
 ||||¡S ©NrR   )r   rS   rT   rU   rJ   r(   r*   rº   r9   r3   r4   rW   )r   rZ   r[   r\   r]   r^   r"   r_   r`   ra   rb   rc   r;   Z	summed_wsZequal_hsrj   rk   rd   rg   rl   rm   rn   ro   r   r   r   rp   B  s(    

        ÿ&
zHBoxDivider.locate)N)NNNN©r„   r…   r†   r‡   rs   rp   r   r   r   r   r»   *  s   	
r»   c                   @   s$   e Zd ZdZddd„Zddd„ZdS )	ÚVBoxDividerzm
    A `.SubplotDivider` for laying out axes vertically, while ensuring that
    they have equal widths.
    Nc                 C   s    t | d|d|dk	r|n|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   Nrq   )r   r[   r]   r   r   r   rs   W  s    zVBoxDivider.new_locatorc                 C   s°   | j jj| j j \}}|  ||¡\}	}
}}|  |¡}|  |¡}t|
|	|||||||  ¡ ƒ	\}}}}|d krnd}|| }}||| |  || ||  |  }}t	j
 ||||¡S r¼   )r   rS   rT   rU   rJ   r*   r(   rº   r9   r3   r4   rW   )r   rZ   r[   r\   r]   r^   r"   r_   r`   ra   rb   rc   r;   Z	summed_hsZequal_wsrk   rj   re   rf   rl   rm   rn   ro   r   r   r   rp   e  s(    

        ÿ
&zVBoxDivider.locate)N)NNNNr½   r   r   r   r   r¾   Q  s   
r¾   c                 C   s$   t | ƒ}|jddd�}|  |¡ |S )Nr   r¦   )rš   rs   r«   )r^   Údividerr®   r   r   r   Úmake_axes_locatablet  s    
rÀ   r}   c                 C   s<   |dkrddddg}t | ƒ}|dk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.
    Nrt   ru   rv   rw   )r   r€   r�   )rÀ   rƒ   )rI   r   r€   r�   r¿   r   r   r   Úmake_axes_area_auto_adjustable|  s    
ÿrÁ   )Nr}   N)r‡   Únumpyr$   Z
matplotlibr§   r   Zmatplotlib.gridspecr   Zmatplotlib.transformsZ
transformsr3   Ú r   r~   r   rr   r�   rš   rº   r»   r¾   rÀ   rÁ   r   r   r   r   Ú<module>   s(    ~2* #!'#	     ÿ