o
    Õj¼$  ã                   @   s¦   d dl mZm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e ed¡ZeeƒZG d	d
„ d
ƒZe edd¡ ZZeeƒ ZZeddœdd„ZeZdS )é    )Ú_apiÚcbookN)ÚBboxé   )ÚAxesc                       s`   e Zd Zdddœ‡ fdd„Z‡ fdd„Z‡ fdd„Z‡ fd	d
„Zdd„ Zdd„ Zdd„ Z	‡  Z
S )ÚParasiteAxesBaseN)Úviewlim_modec                   sB   || _ || _|  |¡ d|d< tƒ j|jdd|jfi |¤Ž d S )NFZframeon)Úroot)Ú_parent_axesÚtransAuxÚset_viewlim_modeÚsuperÚ__init__Z
get_figureZ	_position)ÚselfZparent_axesÚaux_transformr   Úkwargs©Ú	__class__© úf/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/mpl_toolkits/axes_grid1/parasite_axes.pyr   
   s   
ÿ
ÿzParasiteAxesBase.__init__c                    sN   t ƒ  ¡  tj|  ¡ dd | jj| _| jj d| j	¡ | jj d| j	¡ d S )NF)ÚvisibleZxlim_changedZylim_changed)
r   ÚclearÚmartistZsetpÚget_childrenr
   Z
_get_linesÚ	callbacksZ_connect_picklableÚ
_sync_lims©r   r   r   r   r      s   

ÿÿzParasiteAxesBase.clearc                    s@   t ƒ  |¡ |  ¡ D ]}t|jdƒr| |jjv r| |¡ q
d S )NÚ	parasites)r   Úpickr   ÚhasattrZinaxesr   ©r   Z
mouseeventÚar   r   r   r      s   
€ýzParasiteAxesBase.pickc                    sZ   | j d ur&| jj| _| j | jj | _t | j| j¡| _t | j| j¡| _d S tƒ  	¡  d S ©N)
r   r
   Z	transAxesZ	transDataÚmtransformsZblended_transform_factoryZ_xaxis_transformZ_yaxis_transformr   Ú_set_lim_and_transformsr   r   r   r   r$   *   s   

ÿ
ÿz(ParasiteAxesBase._set_lim_and_transformsc                 C   s   t jg d¢|d || _d S )N©NÚequalÚ	transform©Úmode)r   Úcheck_in_listÚ_viewlim_mode)r   r)   r   r   r   r   5   s   
z!ParasiteAxesBase.set_viewlim_modec                 C   s   | j S r"   )r+   r   r   r   r   Úget_viewlim_mode9   s   z!ParasiteAxesBase.get_viewlim_modec                 C   sp   |j  ¡ }|  ¡ }|d u rd S |dkr| j  |¡ d S |dkr-| j  | | j ¡ ¡¡ d S tjg d¢|d d S )Nr&   r'   r%   r(   )	ZviewLimÚfrozenr,   ÚsetZtransformedr   Úinvertedr   r*   )r   ÚparentZviewlimr)   r   r   r   r   <   s   
zParasiteAxesBase._sync_limsr"   )Ú__name__Ú
__module__Ú__qualname__r   r   r   r$   r   r,   r   Ú__classcell__r   r   r   r   r      s    ÿ		r   z
{}Parasitec                       s   e Zd Z‡ fdd„Z	ddd„Z‡ fdd„Z‡ fd	d
„Z‡ fdd„Zddd„Zddd„Z	ddd„Z
dd„ Zdd„ Zddddœ‡ fdd„Z‡  ZS )ÚHostAxesBasec                    s   g | _ tƒ j|i |¤Ž d S r"   )r   r   r   )r   Úargsr   r   r   r   r   Q   s   zHostAxesBase.__init__Nr&   c                 K   sF   |du r| j }t|ƒ}|| |fd|i|¤Ž}| j |¡ | jj|_|S )ad  
        Add a parasite axes to this host.

        Despite this method's name, this should actually be thought of as an
        ``add_parasite_axes`` method.

        .. versionchanged:: 3.7
           Defaults to same base axes class as host axes.

        Parameters
        ----------
        tr : `~matplotlib.transforms.Transform` or None, default: None
            If a `.Transform`, the following relation will hold:
            ``parasite.transData = tr + host.transData``.
            If None, the parasite's and the host's ``transData`` are unrelated.
        viewlim_mode : {"equal", "transform", None}, default: "equal"
            How the parasite's view limits are set: directly equal to the
            parent axes ("equal"), equal after application of *tr*
            ("transform"), or independently (None).
        axes_class : subclass type of `~matplotlib.axes.Axes`, optional
            The `~.axes.Axes` subclass that is instantiated.  If None, the base
            class of the host axes is used.
        **kwargs
            Other parameters are forwarded to the parasite axes constructor.
        Nr   )Ú_base_axes_classÚparasite_axes_class_factoryr   ÚappendÚremoveÚ_remove_method)r   Útrr   Ú
axes_classr   Zparasite_axes_classZax2r   r   r   Úget_aux_axesU   s   ÿÿÿ
zHostAxesBase.get_aux_axesc                    sŒ   t | jƒ}|  ¡ }|r|| |ƒ}| j|dd |  |¡ n|  ¡  |  ¡ }| jD ]}| |¡ | j | ¡ ¡ q(t	ƒ  
|¡ | j|d …= d S )NZactive)Úwhich)ÚlenZ	_childrenZget_axes_locatorZset_positionZapply_aspectZget_positionr   Úextendr   r   Údraw)r   ÚrendererZorig_children_lenZlocatorÚposÚrectÚaxr   r   r   rB   {   s   



zHostAxesBase.drawc                    s"   t ƒ  ¡  | jD ]}| ¡  qd S r"   )r   r   r   )r   rF   r   r   r   r   Ž   s   


ÿzHostAxesBase.clearc                    s&   t ƒ  |¡ | jD ]}| |¡ q	d S r"   )r   r   r   r    r   r   r   r   “   s   
ÿzHostAxesBase.pickc                 C   óB   | j || d}| jd  d¡ |jd  d¡ |jd  d¡ |S )zÈ
        Create a twin of Axes with a shared x-axis but independent y-axis.

        The y-axis of self will have ticks on the left and the returned axes
        will have ticks on the right.
        )ZsharexÚrightFT)ÚleftÚtopÚbottom©Ú_add_twin_axesÚaxisÚset_visible©r   r=   rF   r   r   r   Útwinxš   ó
   zHostAxesBase.twinxc                 C   rG   )zÈ
        Create a twin of Axes with a shared y-axis but independent x-axis.

        The x-axis of self will have ticks on the bottom and the returned axes
        will have ticks on the top.
        )ZshareyrJ   FT)rI   rH   rK   rL   rP   r   r   r   Útwiny§   rR   zHostAxesBase.twinyc                 C   sT   |du rt  ¡ }| j||dd}| jd  d¡ |jd  d¡ |jd  d¡ |S )zÂ
        Create a twin of Axes with no shared axis.

        While self will have ticks on the left and bottom axis, the returned
        axes will have ticks on the top and right axis.
        Nr'   )r   r   )rJ   rH   FT)rI   rK   )r#   ZIdentityTransformrM   rN   rO   )r   Z	aux_transr=   rF   r   r   r   Útwin´   s   ÿzHostAxesBase.twinc                 K   s:   |du r| j }t|ƒ| fi |¤Ž}| j |¡ | j|_|S )zy
        Helper for `.twinx`/`.twiny`/`.twin`.

        *kwargs* are forwarded to the parasite axes constructor.
        N)r7   r8   r   r9   Ú_remove_any_twinr;   )r   r=   r   rF   r   r   r   rM   Ä   s   zHostAxesBase._add_twin_axesc                 C   sd   | j  |¡ ddg}|jr| d¡ |jr| d¡ | jt|ƒ  d¡ | jt|ƒ jddd d S )NrJ   rH   TF)Z
ticklabelsÚlabel)r   r:   Z_sharexZ_shareyrN   ÚtuplerO   Útoggle)r   rF   Zrestorer   r   r   rU   Ñ   s   

zHostAxesBase._remove_any_twinT©Úcall_axes_locatorÚbbox_extra_artistsc                   s@   g ‡ ‡fdd„| j D ƒ¢tƒ jˆˆ |d‘}t dd„ |D ƒ¡S )Nc                    s   g | ]	}|j ˆˆ d ‘qS ))rZ   )Úget_tightbbox)Ú.0rF   ©rZ   rC   r   r   Ú
<listcomp>Þ   s    ÿz.HostAxesBase.get_tightbbox.<locals>.<listcomp>rY   c                 S   s$   g | ]}|j d ks|jd kr|‘qS )r   )ÚwidthÚheight)r]   Úbr   r   r   r_   ã   s   $ )r   r   r\   r   Úunion)r   rC   rZ   r[   Zbbsr   r^   r   r\   Û   s   ÿÿþýzHostAxesBase.get_tightbbox)Nr&   Nr"   )NN)r1   r2   r3   r   r>   rB   r   r   rQ   rS   rT   rM   rU   r\   r4   r   r   r   r   r5   P   s    
ÿ&



ÿr5   z
{}HostAxesr7   )r=   Úfigurec                 O   sH   ddl m} t| ƒ}|du r| ¡ }||g|¢R i |¤Ž}| |¡ |S )aP  
    Create axes that can act as a hosts to parasitic axes.

    Parameters
    ----------
    figure : `~matplotlib.figure.Figure`
        Figure to which the axes will be added. Defaults to the current figure
        `.pyplot.gcf()`.

    *args, **kwargs
        Will be passed on to the underlying `~.axes.Axes` object creation.
    r   N)Zmatplotlib.pyplotZpyplotÚhost_axes_class_factoryZgcfZadd_axes)r=   rd   r6   r   ZpltZhost_axes_classrF   r   r   r   Ú	host_axesë   s   
rf   )Z
matplotlibr   r   Zmatplotlib.artistZartistr   Zmatplotlib.transformsZ
transformsr#   r   Zmpl_axesr   r   Z_make_class_factoryr8   ZParasiteAxesr5   re   Zhost_subplot_class_factoryZHostAxesZSubplotHostrf   Zhost_subplotr   r   r   r   Ú<module>   s"    Cÿ ÿ