
    P/PhU                         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          Z G d	 d
e          Z G d de          Zd Z G d de          Z G d de          Zd Z	 ddZdS )zJ
Helper classes to adjust the positions of multiple axes at drawing time.
    N)_api)SubplotSpec   )	axes_sizec                       e Zd ZdZ	 ddZd Zd Zd Zd Zd	 Z	d
 Z
d Zd Zd Zd Zd ZddZd Zd Zd Zd Zed             Zed             ZddZd Zd Zd d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                     || _         || _        || _        || _        || _        |                     |           || _        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anchors          d/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mpl_toolkits/axes_grid1/axes_divider.py__init__zDivider.__init__   sZ    ( 		%!    c                 h    t          j        fd|                                 D                       S )Nc                 :    g | ]}|                               S  get_size.0srenderers     r   
<listcomp>z0Divider.get_horizontal_sizes.<locals>.<listcomp><   s%    MMM!H--MMMr   )nparrayget_horizontalr   r'   s    `r   get_horizontal_sizeszDivider.get_horizontal_sizes;   s4    xMMMMt7J7J7L7LMMMNNNr   c                 h    t          j        fd|                                 D                       S )Nc                 :    g | ]}|                               S r!   r"   r$   s     r   r(   z.Divider.get_vertical_sizes.<locals>.<listcomp>?   s%    KKK!H--KKKr   )r)   r*   get_verticalr,   s    `r   get_vertical_sizeszDivider.get_vertical_sizes>   s4    xKKKKt7H7H7J7JKKKLLLr   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   s     r   set_positionzDivider.set_positionA   s     			r   c                     | j         S )z%Return the position of the rectangle.r3   r   s    r   get_positionzDivider.get_positionL   s
    yr   c                    t          |t                    r&t          j        t          j        j        |           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   s     r   r   zDivider.set_anchorP   su     fc"" 	={/5fEEEEEFUDM22 	=c&kkQ6F6F;<<<r   c                     | j         S )zReturn the anchor.)r   r6   s    r   
get_anchorzDivider.get_anchord   
    |r   c                     d S Nr!   r6   s    r   get_subplotspeczDivider.get_subplotspech   s    tr   c                     || _         dS )z
        Parameters
        ----------
        h : list of :mod:`~mpl_toolkits.axes_grid1.axes_size`
            sizes for horizontal division
        Nr   )r   hs     r   set_horizontalzDivider.set_horizontalk   s     r   c                     | j         S )zReturn horizontal sizes.rK   r6   s    r   r+   zDivider.get_horizontalt   s    r   c                     || _         dS )z
        Parameters
        ----------
        v : list of :mod:`~mpl_toolkits.axes_grid1.axes_size`
            sizes for vertical division
        Nr   )r   vs     r   set_verticalzDivider.set_verticalx   s     r   c                     | j         S )zReturn vertical sizes.rP   r6   s    r   r0   zDivider.get_vertical   s
    ~r   Fc                     || _         dS )zE
        Parameters
        ----------
        aspect : bool
        Nr   r   r   s     r   
set_aspectzDivider.set_aspect   s     r   c                     | j         S )zReturn aspect.rU   r6   s    r   
get_aspectzDivider.get_aspect   rF   r   c                     || _         d S rH   r   )r   r   s     r   set_locatorzDivider.set_locator   s     r   c                     | j         S rH   r[   r6   s    r   get_locatorzDivider.get_locator   s
    }r   c                 n    | j         |                                 S |                      ||          j        S rH   )r   r7   bounds)r   axr'   s      r   get_position_runtimezDivider.get_position_runtime   s3    = $$&&&==X..55r   c                 J    |                      d          \  }}|r||z
  |z  ndS )Nr   )sum)sizestotalrel_sumabs_sums       r   _calc_kzDivider._calc_k   s1     !99Q<<.5<7**1<r   c                 :    t          j        dg| |dgz            S )Nr   r   )r)   cumsum)re   ks     r   _calc_offsetszDivider._calc_offsets   s$     y!/u1v~/000r   c                     ||dz   }||dz   }| j         }| j        }t          j        | j        ||z
  ||z
  ||z
  ||z
            }| 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_locaterI   )r   nxnynx1ny1xrefyreflocators           r   new_locatorzDivider.new_locator   sq     ;q&C;q&C #L"t)R$Yd
C$JH H"&"6r   c                    || j         z  }|| j         z  }|| j        z  }|| j        z  }| j        j        j        | j        j        z  \  }}|                     ||          \  }	}
}}|                     |          }|                     |          }| 	                    |||z            }| 	                    |||z            }| 
                                rt          ||          }|                     ||          }|                     ||          }|d         |d         z
  |z  }|d         |d         z
  |z  }t          j                            |	|
||          }t          j                            |	|
||          }|                    |                                 |          j        \  }}n0|                     ||          }|                     ||          }|	|
}}|d}|d}|||         |z  z   ||         ||         z
  |z  }}|||         |z  z   ||         ||         z
  |z  }}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   )r   r   r   bboxsizedpirb   r-   r1   ri   rY   minrm   r=   r>   from_boundsanchoredrE   p0)r   rr   rs   rt   ru   axesr'   fig_wfig_hxywrL   hsizesvsizesk_hk_vrl   oxoywwhhpbpb1x0y0x1w1y1h1s                                 r   rq   zDivider._locate   sG    	dot
doty~*TY]:u..tX>>
1a**844((22ll6519--ll6519--?? 	CA##FA..B##FA..BR&2a5.E)BR&2a5.E)B!--aAq99B"..q!R<<C\\$//"3"3R88;FB ##FC00B##FC00BB;C;Cbfun$r#wB'75&@Bbfun$r#wB'75&@B++BB;;;r   c                 z   t          j        g d|           |dk    r-| j                            d|           | xj        dz  c_        d S |dk    r| j                            |           d S |dk    r-| j                            d|           | xj        dz  c_        d S | j                            |           d S )Nleftrightbottomtoppositionr   r   r   r   r   )r   r<   r   insertr   appendr   r   )r   r   r}   s      r   append_sizezDivider.append_size   s    ===$,	. 	. 	. 	.v##At,,,OOq OOOO  ##D)))))!!N!!!T***OOq OOOON!!$'''''r   皙?c                 t    |g d}|D ].}|                      |t          j        ||          |z              /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ds        r   add_auto_adjustable_areaz Divider.add_auto_adjustable_area  s]     <<<K 	N 	NAQ 9(A F F LMMMM	N 	Nr   )Nr	   )FNN)r   N)__name__
__module____qualname____doc__r   r-   r1   r4   r7   r   rE   rI   rM   r+   rR   r0   rW   rY   r\   r^   rb   staticmethodri   rm   ry   rq   r   r   r!   r   r   r   r      s       	 	 &)   >O O OM M M	 	 	    (                    ! ! !  6 6 6 = = \= 1 1 \1
   @-< -< -<^( ( (N N N N N Nr   r   c                   @     e Zd ZdZddddd fd
Zd Zd Zd Z xZS )	SubplotDividerzT
    The Divider class whose rectangle area is specified as a subplot geometry.
    Nr	   r   r   r   r   c                    || _         t                                          |g d|pg |pg ||           |                     t	          j        ||                     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__s          r   r   zSubplotDivider.__init__   sq    6 lll$.$4"x~2 &v 	 	7 	7 	7 	[;CFFGGGGGr   c                 d    |                                                      | j                  j        S )z%Return the bounds of the subplot box.)rI   r7   r   r`   r6   s    r   r7   zSubplotDivider.get_positionA  s'    ##%%224;??FFr   c                     | j         S )zGet the SubplotSpec instance.)_subplotspecr6   s    r   rI   zSubplotDivider.get_subplotspecE  s      r   c                 n    || _         |                     |                    | j                             dS )zSet the SubplotSpec instance.N)r   r4   r7   r   )r   subplotspecs     r   r   zSubplotDivider.set_subplotspecI  s4    '+224;??@@@@@r   )	r   r   r   r   r   r7   rI   r   __classcell__r   s   @r   r   r     s          /3TSH H H H H H HBG G G! ! !A A A A A A Ar   r   c                   f     e Zd ZdZd fd	ZdddZddZddZdddd	Zd
 Z	d Z
d Zd Z xZS )AxesDividerz0
    Divider based on the preexisting axes.
    Nc                 ,   || _         |t          j        |          | _        n|| _        |t          j        |          | _        n|| _        t                                          |                                d| j        g| j        g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   r   rv   rw   r   s       r   r   zAxesDivider.__init__T  s     
<D))DJJDJ<D))DJJDJT__..D%)ZLDJ< $S 	 	2 	2 	2 	2 	2r   )
axes_classc                    | j         }|t          |          } ||                                |                    d          fi |S NT)original)r   typer   r7   )r   r   kwargsr   s       r   _get_new_axeszAxesDivider._get_new_axesj  sZ    zdJz$//++T->->->-M-M $ $"$ $ 	$r   Fc                 (   |t           j        d         | j        z  }|rdnd}|rKt          |t          j                  st	          j        || j                  }|                     ||           t          |t          j                  st	          j        || j                  }|                     ||           |                     |rdnt          | j
                  dz
  | j                  } | 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   rr   rs   r!   )mplrcParamsr   r:   r   _Basefrom_anyr   ry   rB   r   r   r   set_axes_locatorr   r}   r   
pack_startr   r   rx   ra   s           r   new_horizontalzAxesDivider.new_horizontalq  s#    ;,67$*DC"/ff 	'c4:.. BmCdjAAAS#&&&$
++ 	@=DJ???Dd###""=qqC(8$9$9A$= #      T))&))
G$$$	r   c                 (   |t           j        d         | j        z  }|rdnd}|rKt          |t          j                  st	          j        || j                  }|                     ||           t          |t          j                  st	          j        || j                  }|                     ||           |                     | j	        |rdnt          | j                  dz
            } | 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   r:   r   r   r   r   ry   r   rB   r   r   r   r   s           r   new_verticalzAxesDivider.new_vertical  s"    ;,67$*DC$/hh% 	'c4:.. BmCdjAAAS#&&&$
++ 	@=DJ???Dd###"";qqC$7$7!$; # = =  T))&))
G$$$	r   c                    t          j        | j        df| j        df| j        df| j        df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   r}   r   r   r   create_axesr   ra   s	            r   append_axeszAxesDivider.append_axes  s    . #'"4($/)51($/%u-	6
 6

 # # #Z [#O",O OGMO O	2	r   c                 d    | j         #| j                                        }|dk    rdS dS | j         S )NautoFT)r   r   rY   rV   s     r   rY   zAxesDivider.get_aspect  s:    <Z**,,Fut<r   c                 b    | j         "| j                            d          }|j        S | j         S r   )r   r   r7   r`   )r   r|   s     r   r7   zAxesDivider.get_position  s2    9:**D*99D;9r   c                 P    | j         | j                                        S | j         S rH   )r   r   rE   r6   s    r   rE   zAxesDivider.get_anchor  s&    <:((***<r   c                 4    | j                                         S rH   )r   rI   r6   s    r   rI   zAxesDivider.get_subplotspec  s    z))+++r   r   )NFrH   )r   r   r   r   r   r   r   r   r   rY   r7   rE   rI   r   r   s   @r   r   r   O  s         2 2 2 2 2 2, +/ $ $ $ $ $   2   2 $          D            , , , , , , ,r   r   c	                    ||z  }	||z  }
t          |          }|j        \  }}|j        \  }}t          j        g |d          }d|d |df<   ||dd df<   g | |	|                                z
  }t          j                            ||          ^ }}||
k    r|
|z
  |z  }t          j        dg||z  |z             }|d         |d         z
  |z  }|d         \  }}|d         |z  |z   |z  }t          j	        
                    | |||          }t          j	        
                    | |||          }|                    ||          j        \  }}||||fS )Nr   r{   )rB   Tr)   diagrd   linalgsolverk   r=   r>   r   r   r   )r   r   r   rL   summed_widthsequal_heightsr   r   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   s                                r   rq   rq     s   !)KJ 	MA$GW$GW
'1AAbqb"fIAb#2#gJ2G82kGKKMM12A
 iooa++OVV
w&'1 
A56)G35	6	6B
R&2a5.E	!B"1%NFF
)F
V
#u	,B			%	%aAq	1	1B


&
&q!R
4
4C\\&"%%(FBr2r>r   c                   *     e Zd ZdZd fd	Zd Z x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                 L    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   ry   )r   rr   rt   r   s      r   ry   zHBoxDivider.new_locator  s#     ww""2q#q111r   c                    || j         z  }|| j         z  }| j        j        j        | j        j        z  \  }}|                     ||          \  }	}
}}|                     |          }|                     |          }t          |	|
||||||| 	                                	  	        \  }}}}|d}|||         |z  z   ||         ||         z
  |z  }}||}}t          j                            ||||          S Nr{   )r   r   r|   r}   r~   rb   r-   r1   rq   rE   r=   r>   r   )r   rr   rs   rt   ru   r   r'   r   r   r   r   r   rL   	summed_wsequal_hsr   r   r   r   r   r   r   r   s                          r   rq   zHBoxDivider._locate  s   
doty~*TY]:u..tX>>
1a--h77	**844 q!Q	8UE4??;L;LN NBB;Cbfun$r#wB'75&@BRB++BB;;;r   rH   r   r   r   r   ry   rq   r   r   s   @r   r  r    sV         2 2 2 2 2 2< < < < < < <r   r  c                   *     e Zd ZdZd fd	Zd Z xZS )VBoxDividerzm
    A `.SubplotDivider` for laying out axes vertically, while ensuring that
    they have equal widths.
    Nc                 L    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   rs   ru   r   s      r   ry   zVBoxDivider.new_locator3  s#     ww""1b!S111r   c                    || j         z  }|| j         z  }| j        j        j        | j        j        z  \  }}|                     ||          \  }	}
}}|                     |          }|                     |          }t          |
|	||||||| 	                                	  	        \  }}}}|d}||}}|||         |z  z   ||         ||         z
  |z  }}t          j                            ||||          S r  )r   r   r|   r}   r~   rb   r1   r-   rq   rE   r=   r>   r   )r   rr   rs   rt   ru   r   r'   r   r   r   r   r   rL   	summed_hsequal_wsr   r   r   r   r   r   r   r   s                          r   rq   zVBoxDivider._locateA  s   
doty~*TY]:u..tX>>
1a++H55	,,X66 q!Q	8UE4??;L;LN NBB;CRBbfun$r#wB'75&@B++BB;;;r   rH   r  r   s   @r   r
  r
  -  sV         
2 2 2 2 2 2< < < < < < <r   r
  c                 |    t          |           }|                    dd          }|                     |           |S )Nr   r   )r   ry   r   )r   dividerrx   s      r   make_axes_locatabler  R  s@    $G!!Q1!--G'"""Nr   r   c                 h    |g d}t          |           }|| }|                    |||           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   )ra   r   r   r   r  s        r   make_axes_area_auto_adjustabler  Z  s[     888!"%%G$$hC1< % > > > > >r   )Nr   N)r   ro   numpyr)   
matplotlibr   r   matplotlib.gridspecr   matplotlib.transforms
transformsr=    r   r   r   r   r   rq   r  r
  r  r  r!   r   r   <module>r     s                      + + + + + + + + + + + +      HN HN HN HN HN HN HN HNV1A 1A 1A 1A 1AW 1A 1A 1AhN, N, N, N, N,' N, N, N,h  B&< &< &< &< &<. &< &< &<R"< "< "< "< "<. "< "< "<J   15> > > > > >r   