
    gL                        d Z ddlmZmZ ddlmZ ddlmZm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e      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Zd Zej6                  	 	 	 	 dd       Zej6                  	 	 	 	 dd       Z G d de      Zej6                  d        Zy)zK
A collection of functions and objects for creating or placing inset axes.
    )_api
_docstring)AnchoredOffsetbox)Patch	Rectangle)Path)Bbox)IdentityTransformTransformedBbox   )	axes_size)HostAxesc                   .     e Zd Z	 d fd	Zd Zd Z xZS )AnchoredLocatorBasec                 0    t         |   |dd |||       y )Ng        )padchild	borderpadbbox_to_anchorbbox_transform)super__init__)selfr   	offsetboxlocr   r   	__class__s         b/var/www/dash_apps/app1/venv/lib/python3.12/site-packages/mpl_toolkits/axes_grid1/inset_locator.pyr   zAnchoredLocatorBase.__init__   s#    Rty). 	 	
    c                     t        d      )NzNo draw method should be called)RuntimeError)r   renderers     r   drawzAnchoredLocatorBase.draw   s    <==r   c                 v   |j                  d      }||j                         }|| _        | j                  |      }| j	                  |j
                  |j                  dd|      \  }}t        j                  |||j
                  |j                        }|j                  j                         }t        ||      S )NFrootr   )
get_figure_get_rendereraxesget_window_extent
get_offsetwidthheightr	   from_boundstransSubfigureinvertedr   )	r   axr!   figbboxpxpybbox_canvastrs	            r   __call__zAnchoredLocatorBase.__call__   s    mmm'((*H	%%h/T[[!QIB&&r2tzz4;;G((*{B//r         ?N)__name__
__module____qualname__r   r"   r7   __classcell__r   s   @r   r   r      s    /3
>	0r   r   c                   (     e Zd Z	 d fd	Zd Z xZS )AnchoredSizeLocatorc                     t         |   |d |||       t        j                  |      | _        t        j                  |      | _        y N)r   r   )r   r   Sizefrom_anyx_sizey_size)r   r   rE   rF   r   r   r   r   s          r   r   zAnchoredSizeLocator.__init__(   sC    D# 	 	

 mmF+mmF+r   c                    | j                         }|j                  d      }| j                  j                  |      \  }}|j                  |z  ||z  z   }| j
                  j                  |      \  }}|j                  |z  ||z  z   }|j                  | j                  j                               }| j                  |z  }	t        j                  dd||      j                  |	      S )Ng      R@r   )get_bbox_to_anchorpoints_to_pixelsrE   get_sizer+   rF   r,   propget_size_in_pointsr   r	   r-   padded)
r   r!   r2   dpirar+   r,   fontsizer   s
             r   get_bboxzAnchoredSizeLocator.get_bbox2   s    &&('',{{##H-1

QS({{##H-1q1s7*,,TYY-I-I-KLhh!1eV4;;C@@r   r8   r:   r;   r<   r   rR   r=   r>   s   @r   r@   r@   '   s    /3,Ar   r@   c                   ,     e Zd Z	 	 	 d fd	Zd Z xZS )AnchoredZoomLocatorc                 f    || _         || _        ||j                  }t        |   |d |||       y rB   )parent_axeszoomr2   r   r   )r   rW   rX   r   r   r   r   r   s          r   r   zAnchoredZoomLocator.__init__B   sC     '	!(--ND#) 	 	+r   c           	         | j                   j                  j                  | j                  j                        }|j                  | j                  j                               }| j                  |z  }t        j                  ddt        |j                  | j                  z        t        |j                  | j                  z              j                  |      S Nr   )rW   	transDatatransform_bboxr(   viewLimrI   rK   rL   r   r	   r-   absr+   rX   r,   rM   )r   r!   bbrQ   r   s        r   rR   zAnchoredZoomLocator.get_bboxN   s    ''66tyy7H7HI,,TYY-I-I-KLhh!1c"((TYY./RYY5J1KMVC[	r   )r9   NNrS   r>   s   @r   rU   rU   A   s     $ $
+r   rU   c                   B     e Zd Zej                   fd       Zd Z xZS )	BboxPatchc                 j    d|v rt        d      t               |d<   t        |   di | || _        y)a-  
        Patch showing the shape bounded by a Bbox.

        Parameters
        ----------
        bbox : `~matplotlib.transforms.Bbox`
            Bbox to use for the extents of this patch.

        **kwargs
            Patch properties. Valid arguments include:

            %(Patch:kwdoc)s
        	transformtransform should not be setN )
ValueErrorr
   r   r   r2   )r   r2   kwargsr   s      r   r   zBboxPatch.__init__Y   s=     & :;;/1{"6"	r   c                 z    | j                   j                  \  }}}}t        j                  ||f||f||f||fg      S N)r2   extentsr   _create_closed)r   x0y0x1y1s        r   get_pathzBboxPatch.get_patho   sC    **BB""RHr2hR2r(#KLLr   r:   r;   r<   r   interpdr   rp   r=   r>   s   @r   ra   ra   X   s!     *Mr   ra   c                   f     e Zd Zed        Zedd       Zej                  d fd	       Zd Z	 xZ
S )BboxConnectorc                 n    | j                   \  }}}}|dk(  r||fS |dk(  r||fS |dk(  r||fS |dk(  r||fS y)z
        Return the ``(x, y)`` coordinates of corner *loc* of *bbox*; parameters
        behave as documented for the `.BboxConnector` constructor.
        r            N)rj   )r2   r   rl   rm   rn   ro   s         r   get_bbox_edge_poszBboxConnector.get_bbox_edge_posv   sZ     BB!8r6MAXr6MAXr6MAXr6M r   c                    t        | t              r,t        t        j                         | j                               } t        |t              r,t        t        j                         |j                               }||}t        j                  | |      \  }}t        j                  ||      \  }}t        ||g||gg      S )z
        Construct a `.Path` connecting corner *loc1* of *bbox1* to corner
        *loc2* of *bbox2*, where parameters behave as documented as for the
        `.BboxConnector` constructor.
        )	
isinstancer   r   r	   unitget_transformrt   ry   r   )bbox1bbox2loc1loc2rn   ro   x2y2s           r   connect_bboxzBboxConnector.connect_bbox   s     eY'#DIIK1D1D1FGEeY'#DIIK1D1D1FGE<D00=B00=Bb"XBx())r   c                     d|v rt        d      t               |d<   |j                  dt        h dj	                  |                   t        |   di | || _        || _        || _	        || _
        y)ap  
        Connect two bboxes with a straight line.

        Parameters
        ----------
        bbox1, bbox2 : `~matplotlib.transforms.Bbox`
            Bounding boxes to connect.

        loc1, loc2 : {1, 2, 3, 4}
            Corner of *bbox1* and *bbox2* to draw the line. Valid values are::

                'upper right'  : 1,
                'upper left'   : 2,
                'lower left'   : 3,
                'lower right'  : 4

            *loc2* is optional and defaults to *loc1*.

        **kwargs
            Patch properties for the line drawn. Valid arguments include:

            %(Patch:kwdoc)s
        rc   rd   fill>   fccolor	facecolorNre   )rf   r
   
setdefaultboolintersectionr   r   r~   r   r   r   )r   r~   r   r   r   rg   r   s         r   r   zBboxConnector.__init__   sw    2 & :;;/1{D5BB6JK	M"6"

		r   c                 z    | j                  | j                  | j                  | j                  | j                        S ri   )r   r~   r   r   r   )r   s    r   rp   zBboxConnector.get_path   s.      TZZ!%DII7 	7r   ri   )r:   r;   r<   staticmethodry   r   r   rr   r   rp   r=   r>   s   @r   rt   rt   u   sI      * *  " "H7r   rt   c                   B     e Zd Zej                   fd       Zd Z xZS )BboxConnectorPatchc                 f    d|v rt        d      t        |   ||||fi | || _        || _        y)a  
        Connect two bboxes with a quadrilateral.

        The quadrilateral is specified by two lines that start and end at
        corners of the bboxes. The four sides of the quadrilateral are defined
        by the two lines given, the line between the two corners specified in
        *bbox1* and the line between the two corners specified in *bbox2*.

        Parameters
        ----------
        bbox1, bbox2 : `~matplotlib.transforms.Bbox`
            Bounding boxes to connect.

        loc1a, loc2a, loc1b, loc2b : {1, 2, 3, 4}
            The first line connects corners *loc1a* of *bbox1* and *loc2a* of
            *bbox2*; the second line connects corners *loc1b* of *bbox1* and
            *loc2b* of *bbox2*.  Valid values are::

                'upper right'  : 1,
                'upper left'   : 2,
                'lower left'   : 3,
                'lower right'  : 4

        **kwargs
            Patch properties for the line drawn:

            %(Patch:kwdoc)s
        rc   rd   N)rf   r   r   loc1bloc2b)	r   r~   r   loc1aloc2ar   r   rg   r   s	           r   r   zBboxConnectorPatch.__init__   s?    < & :;;ue>v>

r   c                 Z   | j                  | j                  | j                  | j                  | j                        }| j                  | j                  | j                  | j
                  | j                        }g |j                  |j                  |j                  d   }t        |      S rZ   )	r   r~   r   r   r   r   r   verticesr   )r   path1path2path_mergeds       r   rp   zBboxConnectorPatch.get_path   s    !!$**djj$))TYYO!!$**djj"&**djj:KKK9JKK  r   rq   r>   s   @r   r   r      s!    ! !F!r   r   c                     |t         }|i }| j                  d      } ||| j                         fi ddi|d|i}|j                  |      S )zBHelper function to add an inset axes and disable navigation in it.Fr$   navigateaxes_locator)r   r&   get_positionadd_axes)rW   
axes_classaxes_kwargsr   r1   
inset_axess         r   _add_inset_axesr      so    


 
 e
 
,C[%%'Lu
J
J^\
JLJ <<
##r   Nc	                 p   || j                   | j                  d      j                  fv r|t        j                  d       d}|| j
                  }t        |t              r9t        |t              st        |t              rt        |      dk7  rt        d      t        | ||t        ||||||            S )ah  
    Create an inset axes with a given width and height.

    Both sizes used can be specified either in inches or percentage.
    For example,::

        inset_axes(parent_axes, width='40%%', height='30%%', loc='lower left')

    creates in inset axes in the lower left corner of *parent_axes* which spans
    over 30%% in height and 40%% in width of the *parent_axes*. Since the usage
    of `.inset_axes` may become slightly tricky when exceeding such standard
    cases, it is recommended to read :doc:`the examples
    </gallery/axes_grid1/inset_locator_demo>`.

    Notes
    -----
    The meaning of *bbox_to_anchor* and *bbox_to_transform* is interpreted
    differently from that of legend. The value of bbox_to_anchor
    (or the return value of its get_points method; the default is
    *parent_axes.bbox*) is transformed by the bbox_transform (the default
    is Identity transform) and then interpreted as points in the pixel
    coordinate (which is dpi dependent).

    Thus, following three calls are identical and creates an inset axes
    with respect to the *parent_axes*::

       axins = inset_axes(parent_axes, "30%%", "40%%")
       axins = inset_axes(parent_axes, "30%%", "40%%",
                          bbox_to_anchor=parent_axes.bbox)
       axins = inset_axes(parent_axes, "30%%", "40%%",
                          bbox_to_anchor=(0, 0, 1, 1),
                          bbox_transform=parent_axes.transAxes)

    Parameters
    ----------
    parent_axes : `matplotlib.axes.Axes`
        Axes to place the inset axes.

    width, height : float or str
        Size of the inset axes to create. If a float is provided, it is
        the size in inches, e.g. *width=1.3*. If a string is provided, it is
        the size in relative units, e.g. *width='40%%'*. By default, i.e. if
        neither *bbox_to_anchor* nor *bbox_transform* are specified, those
        are relative to the parent_axes. Otherwise, they are to be understood
        relative to the bounding box provided via *bbox_to_anchor*.

    loc : str, default: 'upper right'
        Location to place the inset axes.  Valid locations are
        'upper left', 'upper center', 'upper right',
        'center left', 'center', 'center right',
        'lower left', 'lower center', 'lower right'.
        For backward compatibility, numeric values are accepted as well.
        See the parameter *loc* of `.Legend` for details.

    bbox_to_anchor : tuple or `~matplotlib.transforms.BboxBase`, optional
        Bbox that the inset axes will be anchored to. If None,
        a tuple of (0, 0, 1, 1) is used if *bbox_transform* is set
        to *parent_axes.transAxes* or *parent_axes.figure.transFigure*.
        Otherwise, *parent_axes.bbox* is used. If a tuple, can be either
        [left, bottom, width, height], or [left, bottom].
        If the kwargs *width* and/or *height* are specified in relative units,
        the 2-tuple [left, bottom] cannot be used. Note that,
        unless *bbox_transform* is set, the units of the bounding box
        are interpreted in the pixel coordinate. When using *bbox_to_anchor*
        with tuple, it almost always makes sense to also specify
        a *bbox_transform*. This might often be the axes transform
        *parent_axes.transAxes*.

    bbox_transform : `~matplotlib.transforms.Transform`, optional
        Transformation for the bbox that contains the inset axes.
        If None, a `.transforms.IdentityTransform` is used. The value
        of *bbox_to_anchor* (or the return value of its get_points method)
        is transformed by the *bbox_transform* and then interpreted
        as points in the pixel coordinate (which is dpi dependent).
        You may provide *bbox_to_anchor* in some normalized coordinate,
        and give an appropriate transform (e.g., *parent_axes.transAxes*).

    axes_class : `~matplotlib.axes.Axes` type, default: `.HostAxes`
        The type of the newly created inset axes.

    axes_kwargs : dict, optional
        Keyword arguments to pass to the constructor of the inset axes.
        Valid arguments include:

        %(Axes:kwdoc)s

    borderpad : float, default: 0.5
        Padding between inset axes and the bbox_to_anchor.
        The units are axes font size, i.e. for a default font size of 10 points
        *borderpad = 0.5* is equivalent to a padding of 5 points.

    Returns
    -------
    inset_axes : *axes_class*
        Inset axes object created.
    Fr$   zUsing the axes or figure transform requires a bounding box in the respective coordinates. Using bbox_to_anchor=(0, 0, 1, 1) now.)r   r   r   r   rx   zoUsing relative units for width or height requires to provide a 4-tuple or a `Bbox` instance to `bbox_to_anchor.)r   r   r   )	transAxesr&   transFigurer   warn_externalr2   r{   tuplestrlenrf   r   r@   )	rW   r+   r,   r   r   r   r   r   r   s	            r   r   r      s    L 	;00&11u1=IIK 	K& D 	E &$))>5)s#z&#'>~!# C D D ZE6s)Y	@A Ar   c                 <    t        | ||t        | |||||            S )a  
    Create an anchored inset axes by scaling a parent axes. For usage, also see
    :doc:`the examples </gallery/axes_grid1/inset_locator_demo2>`.

    Parameters
    ----------
    parent_axes : `~matplotlib.axes.Axes`
        Axes to place the inset axes.

    zoom : float
        Scaling factor of the data axes. *zoom* > 1 will enlarge the
        coordinates (i.e., "zoomed in"), while *zoom* < 1 will shrink the
        coordinates (i.e., "zoomed out").

    loc : str, default: 'upper right'
        Location to place the inset axes.  Valid locations are
        'upper left', 'upper center', 'upper right',
        'center left', 'center', 'center right',
        'lower left', 'lower center', 'lower right'.
        For backward compatibility, numeric values are accepted as well.
        See the parameter *loc* of `.Legend` for details.

    bbox_to_anchor : tuple or `~matplotlib.transforms.BboxBase`, optional
        Bbox that the inset axes will be anchored to. If None,
        *parent_axes.bbox* is used. If a tuple, can be either
        [left, bottom, width, height], or [left, bottom].
        If the kwargs *width* and/or *height* are specified in relative units,
        the 2-tuple [left, bottom] cannot be used. Note that
        the units of the bounding box are determined through the transform
        in use. When using *bbox_to_anchor* it almost always makes sense to
        also specify a *bbox_transform*. This might often be the axes transform
        *parent_axes.transAxes*.

    bbox_transform : `~matplotlib.transforms.Transform`, optional
        Transformation for the bbox that contains the inset axes.
        If None, a `.transforms.IdentityTransform` is used (i.e. pixel
        coordinates). This is useful when not providing any argument to
        *bbox_to_anchor*. When using *bbox_to_anchor* it almost always makes
        sense to also specify a *bbox_transform*. This might often be the
        axes transform *parent_axes.transAxes*. Inversely, when specifying
        the axes- or figure-transform here, be aware that not specifying
        *bbox_to_anchor* will use *parent_axes.bbox*, the units of which are
        in display (pixel) coordinates.

    axes_class : `~matplotlib.axes.Axes` type, default: `.HostAxes`
        The type of the newly created inset axes.

    axes_kwargs : dict, optional
        Keyword arguments to pass to the constructor of the inset axes.
        Valid arguments include:

        %(Axes:kwdoc)s

    borderpad : float, default: 0.5
        Padding between inset axes and the bbox_to_anchor.
        The units are axes font size, i.e. for a default font size of 10 points
        *borderpad = 0.5* is equivalent to a padding of 5 points.

    Returns
    -------
    inset_axes : *axes_class*
        Inset axes object created.
    )rX   r   r   r   r   )r   rU   )rW   rX   r   r   r   r   r   r   s           r   zoomed_inset_axesr   y  s0    J Zd).	!" "r   c                   ,     e Zd ZdZ fdZ fdZ xZS )_TransformedBboxWithCallbackz
    Variant of `.TransformBbox` which calls *callback* before returning points.

    Used by `.mark_inset` to unstale the parent axes' viewlim as needed.
    c                2    t        |   |i | || _        y ri   )r   r   	_callback)r   callbackargsrg   r   s       r   r   z%_TransformedBboxWithCallback.__init__  s    $)&)!r   c                 @    | j                          t        | 	         S ri   )r   r   
get_points)r   r   s    r   r   z'_TransformedBboxWithCallback.get_points  s    w!##r   )r:   r;   r<   __doc__r   r   r=   r>   s   @r   r   r     s    "$ $r   r   c                    t        |j                  | j                  | j                        }|j	                  dt        h dj                  |                   t        |fi |}| j                  |       t        |j                  |fd|i|}|j                  |       |j                  d       t        |j                  |fd|i|}|j                  |       |j                  d       |||fS )a  
    Draw a box to mark the location of an area represented by an inset axes.

    This function draws a box in *parent_axes* at the bounding box of
    *inset_axes*, and shows a connection with the inset axes by drawing lines
    at the corners, giving a "zoomed in" effect.

    Parameters
    ----------
    parent_axes : `~matplotlib.axes.Axes`
        Axes which contains the area of the inset axes.

    inset_axes : `~matplotlib.axes.Axes`
        The inset axes.

    loc1, loc2 : {1, 2, 3, 4}
        Corners to use for connecting the inset axes and the area in the
        parent axes.

    **kwargs
        Patch properties for the lines and box drawn:

        %(Patch:kwdoc)s

    Returns
    -------
    pp : `~matplotlib.patches.Patch`
        The patch drawn to represent the area of the inset axes.

    p1, p2 : `~matplotlib.patches.Patch`
        The patches connecting two corners of the inset axes and its area.
    )r   r   >   r   r   r   r   F)r   r]   r[   _unstale_viewLimr   r   r   ra   	add_patchrt   r2   set_clip_on)	rW   r   r   r   rg   rectppp1p2s	            r   
mark_insetr     s    D (K11--/D fd#?#L#LV#TUV	4	"6	"B"	z	B4	B6	BBNN5	z	B4	B6	BBNN5r2:r   )zupper rightNNNNr9   ) r   
matplotlibr   r   matplotlib.offsetboxr   matplotlib.patchesr   r   matplotlib.pathr   matplotlib.transformsr	   r
   r    r   rC   parasite_axesr   r   r@   rU   ra   rt   r   r   rr   r   r   r   r   re   r   r   <module>r      s    ( 2 /   & D  #0+ 0.A- A4- .M M:J7E J7Z+! +!\
$ /<37,0xA xAv -::>37 #I" I"X$? $  0 0r   