o
    gX6                     @   sF  d dl Z d dlmZ d dl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 ddd	d
ZeeZejdddG dd dZejdd
de ddddZe  eeZW d   n1 sow   Y  G dd dZe ddddZdd ZeeZe
eZeddddZeddddZdS )    N)_api)subplot_class_factory)Bbox   )Axesc                       s   e Zd Zddd fddZ fddZdd Z fd	d
Z fddZdd Zdd Z	e
jddddd Zdd Zd fdd	Z  ZS )ParasiteAxesBaseNviewlim_modec                   s<   || _ || _| | d|d< t j|j|jfi | d S )NFframeon)_parent_axestransAuxset_viewlim_modesuper__init__figure	_positionselfparent_axesaux_transformr	   kwargs	__class__ c/home/ubuntu/cloudmapper/venv/lib/python3.10/site-packages/mpl_toolkits/axes_grid1/parasite_axes.pyr      s
   
zParasiteAxesBase.__init__c                    s*   t    tj|  dd | jj| _d S )NF)visible)r   clamartistsetpget_childrenr   
_get_linesr   r   r   r   r      s   
zParasiteAxesBase.clac                 C   s6   dd |   D }dd | jD }t|t|| fS )Nc                 S      h | ]}|  r|qS r   get_visible.0ar   r   r   	<setcomp>       z6ParasiteAxesBase.get_images_artists.<locals>.<setcomp>c                 S   r"   r   r#   r%   r   r   r   r(      r)   )r   imageslist)r   artistsr*   r   r   r   get_images_artists   s   z#ParasiteAxesBase.get_images_artistsc                    s@   t  | |  D ]}t|jdr| |jjv r|| q
d S )N	parasites)r   pickr   hasattrinaxesr.   r   
mouseeventr'   r   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   	transAxes	transDatamtransformsblended_transform_factory_xaxis_transform_yaxis_transformr   _set_lim_and_transformsr!   r   r   r   r;   -   s   


z(ParasiteAxesBase._set_lim_and_transformsc                 C      t jg d|d || _d S NNequal	transformmoder   check_in_list_viewlim_moder   rB   r   r   r   r   8      
z!ParasiteAxesBase.set_viewlim_modec                 C      | j S r4   rE   r!   r   r   r   get_viewlim_mode<      z!ParasiteAxesBase.get_viewlim_mode3.4apply_aspectalternativec                 C   rH   r4   _update_viewlimr!   r   r   r   update_viewlim?   s   zParasiteAxesBase.update_viewlimc                 C   v   | j j }|  }|d u rd S |dkr| jj| d S |dkr0| jj|| j  d S t	j
g d|d d S Nr?   r@   r>   rA   r   viewLimfrozenrJ   axessettransformedr   invertedr   rD   r   viewlimrB   r   r   r   rQ   C      z ParasiteAxesBase._update_viewlimc                       |    t   d S r4   rQ   r   rM   r   positionr   r   r   rM   P      zParasiteAxesBase.apply_aspectr4   )__name__
__module____qualname__r   r   r-   r/   r;   r   rJ   r   
deprecatedrR   rQ   rM   __classcell__r   r   r   r   r      s    
r   c                 C   s0   | d u rt jddd t} td| j t| fi S )N3.3zSupport for passing None to parasite_axes_class_factory is deprecated since %(since)s and will be removed %(removal)s; explicitly pass the default Axes class instead.messagez
%sParasite)r   warn_deprecatedr   typerd   r   
axes_classr   r   r   parasite_axes_class_factoryW   s   
rp   rL   rN   c                       sb   e Zd Zd fdd	Zdd Zdd Zdd	 Zejd
dddd Z	dd Z
d fdd	Z  ZS )ParasiteAxesAuxTransBaseNc                    s   t  j||fd|i| d S )Nr	   )r   r   r   r   r   r   r   j   s
   
z!ParasiteAxesAuxTransBase.__init__c                 C   sB   | j j| _| j| j j | _t| j| j| _t| j| j| _d S r4   )r   r5   r   r6   r7   r8   r9   r:   r!   r   r   r   r;   p   s   

z0ParasiteAxesAuxTransBase._set_lim_and_transformsc                 C   r<   r=   rC   rF   r   r   r   r   x   rG   z)ParasiteAxesAuxTransBase.set_viewlim_modec                 C   rH   r4   rI   r!   r   r   r   rJ   |   rK   z)ParasiteAxesAuxTransBase.get_viewlim_moderL   rM   rN   c                 C   s   |   S r4   rP   r!   r   r   r   rR      s   z'ParasiteAxesAuxTransBase.update_viewlimc                 C   rS   rT   rU   r\   r   r   r   rQ      r^   z(ParasiteAxesAuxTransBase._update_viewlimc                    r_   r4   r`   ra   r   r   r   rM      rc   z%ParasiteAxesAuxTransBase.apply_aspectr4   )rd   re   rf   r   r;   r   rJ   r   rg   rR   rQ   rM   rh   r   r   r   r   rq   h   s    
rq   c                 C   sN   | d u rt jddd t}nt| tst| }n| }td|j t|fddiS )Nri   zSupport for passing None to parasite_axes_auxtrans_class_factory is deprecated since %(since)s and will be removed %(removal)s; explicitly pass the default ParasiteAxes class instead.rj   z%sParasiteAuxTransnameparasite_axes)	r   rl   ParasiteAxes
issubclassr   rp   rm   rd   rq   )ro   parasite_axes_classr   r   r   $parasite_axes_auxtrans_class_factory   s   


rw   c                       s   e Zd Z fddZddefddZd f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 fdd	Z  ZS )HostAxesBasec                    s   g | _ t j|i | d S r4   )r.   r   r   )r   argsr   r   r   r   r      s   zHostAxesBase.__init__Nr?   c                 C   s0   t |}|| ||d}| j| | jj|_|S )a  
        Add a parasite axes to this host.

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

        *tr* may be `.Transform`, in which case the following relation will
        hold: ``parasite.transData = tr + host.transData``.  Alternatively, it
        may be None (the default), no special relationship will hold between
        the parasite's and the host's ``transData``.
        r   )rp   r.   appendremove_remove_method)r   trr	   ro   rv   ax2r   r   r   get_aux_axes   s
   
zHostAxesBase.get_aux_axesc                    s*   t   }| jD ]
}||| q|S r4   )r   _get_legend_handlesr.   extend)r   legend_handler_mapall_handlesaxr   r   r   r      s   

z HostAxesBase._get_legend_handlesc           
         s   t | j}t | j}t| dr,|  }|r'|| |}| j|dd | | n	|   n|   |  }| jD ]}|| |	 \}}	| j
| | j
|	 q7t | || _|| _d S )Nget_axes_locatoractive)which)r+   r,   r*   r0   r   set_positionrM   get_positionr.   r-   r   r   draw)
r   rendererorig_artistsorig_imageslocatorposrectr   r*   r,   r   r   r   r      s&   







zHostAxesBase.drawc                    s"   | j D ]}|  qt   d S r4   )r.   r   r   )r   r   r   r   r   r      s   

zHostAxesBase.clac                    s&   t  | | jD ]}|| q	d S r4   )r   r/   r.   r2   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.
        )sharexrightFT)lefttopbottom_add_twin_axesaxisset_visibler   ro   r   r   r   r   twinx   
   zHostAxesBase.twinxc                 C   r   )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.
        )shareyr   FT)r   r   r   r   r   r   r   r   twiny  r   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	   )r   r   FT)r   r   )r7   IdentityTransformr   r   r   )r   	aux_transro   r   r   r   r   twin  s   zHostAxesBase.twinc                 K   s<   |du r|   }t|| fi |}| j| | j|_|S )zy
        Helper for `.twinx`/`.twiny`/`.twin`.

        *kwargs* are forwarded to the parasite axes constructor.
        N)_get_base_axesrp   r.   rz   _remove_any_twinr|   )r   ro   r   r   r   r   r   r     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 )Nr   r   TF)
ticklabelslabel)r.   r{   _sharex_shareyr   tupler   toggle)r   r   restorer   r   r   r   +  s   

zHostAxesBase._remove_any_twinTc                    s@   g  fdd| j D t j |d}tdd |D S )Nc                    s   g | ]	}|j  d qS ))call_axes_locator)get_tightbbox)r&   r   r   r   r   r   
<listcomp>8  s    z.HostAxesBase.get_tightbbox.<locals>.<listcomp>)r   bbox_extra_artistsc                 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   r   r   r   bbsr   r   r   r   5  s   zHostAxesBase.get_tightbboxr4   )NN)TN)rd   re   rf   r   r   r   r   r   r   r/   r   r   r   r   r   r   rh   r   r   r   r   rx      s    



rx   c                    s@    d u rt jddd t  fdd}td j t fd|iS )Nri   zSupport for passing None to host_axes_class is deprecated since %(since)s and will be removed %(removed)s; explicitly pass the default Axes class instead.rj   c                    s    S r4   r   r!   rn   r   r   r   I  s   z/host_axes_class_factory.<locals>._get_base_axesz
%sHostAxesr   )r   rl   r   rm   rd   rx   )ro   r   r   rn   r   host_axes_class_factory@  s   
r   c                 C   s   t | }t|}|S r4   )r   r   )ro   host_axes_classsubplot_host_classr   r   r   host_subplot_class_factoryQ  s   r   )ro   r   c                 O   P   ddl m} t| }|du r| }||g|R i |}|| |  |S )aJ  
    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`` object creation.
    r   N)matplotlib.pyplotpyplotr   gcfadd_axesdraw_if_interactive)ro   r   ry   r   pltr   r   r   r   r   	host_axes[     
r   c                 O   r   )aQ  
    Create a subplot that can act as a host to parasitic axes.

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

    *args, **kwargs
        Will be passed on to the underlying ``Axes`` object creation.
    r   N)r   r   r   r   add_subplotr   )ro   r   ry   r   r   host_subplot_classr   r   r   r   host_subplotr  r   r   r4   )	functools
matplotlibr   matplotlib.artistartistr   matplotlib.transforms
transformsr7   matplotlib.axesr   r   mpl_axesr   r   	lru_cacherp   rt   rg   rq   rw   'suppress_matplotlib_deprecation_warningParasiteAxesAuxTransrx   r   r   HostAxesSubplotHostr   r   r   r   r   r   <module>   s8    L,

 