o
    i?8                     @   s   d dl Z d dlmZmZmZ d dlmZ d dl	m
Z
 ddlmZ d dlZG dd dZe ddd	d
ZeeZG dd dZe ddddZeeZ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)artistcbook
transforms)subplot_class_factory)Bbox   )Axesc                       s<   e Zd Zdd Z fddZ fddZ fddZ  ZS )	ParasiteAxesBasec                 C   s6   dd |   D }dd | jD }t|t|| fS )Nc                 S      h | ]}|  r|qS  get_visible.0ar   r   `/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/mpl_toolkits/axes_grid1/parasite_axes.py	<setcomp>       z6ParasiteAxesBase.get_images_artists.<locals>.<setcomp>c                 S   r
   r   r   r   r   r   r   r      r   )get_childrenimageslist)selfartistsr   r   r   r   get_images_artists   s   z#ParasiteAxesBase.get_images_artistsc                    s,   || _ d|d< t j|j|jfi | d S )NFframeon)_parent_axessuper__init__figure	_position)r   parent_axeskwargs	__class__r   r   r      s   zParasiteAxesBase.__init__c                    sd   t    tj|  dd | jj| _| jr$| j	d | j
	d d S | j	d | j
	d d S )NF)visibleg      ?g      @)r   clamartistsetpr   r   
_get_lines
_axisbelowxaxis
set_zorderyaxisr   r"   r   r   r%      s   

zParasiteAxesBase.clac                    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.pick)__name__
__module____qualname__r   r   r%   r/   __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   typer4   r	   
axes_classr   r   r   parasite_axes_class_factory4   s   
r?   c                       s   e Zd Zd fdd	Zdd Zdd Zdd	 Zd
d Zdd Z fddZ	 fddZ
dd Z fddZ fddZd fdd	Z  ZS )ParasiteAxesAuxTransBaseNc                    s(   || _ | | t j|fi | d S N)transAuxset_viewlim_moder   r   )r   r    aux_transformviewlim_moder!   r"   r   r   r   F   s   
z!ParasiteAxesAuxTransBase.__init__c                 C   sB   | j j| _| j| j j | _t| j| j| _t| j| j| _d S rA   )r   	transAxesrB   	transDatamtransformsblended_transform_factory_xaxis_transform_yaxis_transformr-   r   r   r   _set_lim_and_transformsL   s   

z0ParasiteAxesAuxTransBase._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   rQ   r   r   r   rC   Y   s   
z)ParasiteAxesAuxTransBase.set_viewlim_modec                 C   s   | j S rA   )rS   r-   r   r   r   get_viewlim_mode]   s   z)ParasiteAxesAuxTransBase.get_viewlim_modec                 C   sv   | 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 )NrN   rO   rM   rP   )r   viewLimfrozenrT   axessettransformedrB   invertedr   rR   )r   viewlimrQ   r   r   r   update_viewlim`   s   z'ParasiteAxesAuxTransBase.update_viewlimc                 O   s   t |dkr$|d }|j\}}td|}td|}t||\}	}
n|\}	}
}d|v r9||	|
|fi |}|S |	j}t|	j|
jg}| j|}|d d df 	|}|d d df 	|}||||fi |}|
| jj |S )Nr   r   g      rO   )lenshapenparangemeshgridcolumn_stackflatrB   rO   reshapeset_transformr   rG   )r   super_pcolorXYCr!   CnynxgxgyXYmesh
orig_shapexytwxyr   r   r   _pcolorm   s$   


z ParasiteAxesAuxTransBase._pcolorc                       | j t jg|R i |S rA   )rs   r   
pcolormeshr   rg   r!   r"   r   r   ru         z#ParasiteAxesAuxTransBase.pcolormeshc                    rt   rA   )rs   r   pcolorrv   r"   r   r   rx      rw   zParasiteAxesAuxTransBase.pcolorc                 O   s  t |dkr&|d }|j\}}td|}td|}t||\}	}
|}n|d d \}	}
|dd  }d|v rF||	|
g|R i |}|S |	j}t|	j|
jg}| j|}|d d df 	|}|d d df 	|}|||g|R i |}|j
D ]	}|| jj q}|S )N   r   g        rO   r   )r]   r^   r_   r`   ra   rb   rc   rB   rO   rd   collectionsre   r   rG   )r   super_contourXYCLr!   rh   ri   rj   rk   rl   rm   rn   CLcontrp   rq   rr   cr   r   r   _contour   s*   

z!ParasiteAxesAuxTransBase._contourc                    rt   rA   )r   r   contourr   r|   r!   r"   r   r   r      rw   z ParasiteAxesAuxTransBase.contourc                    rt   rA   )r   r   contourfr   r"   r   r   r      rw   z!ParasiteAxesAuxTransBase.contourfc                    s   |    t   d S rA   )r\   r   apply_aspect)r   positionr"   r   r   r      s   z%ParasiteAxesAuxTransBase.apply_aspectrA   )r4   r5   r6   r   rL   rC   rT   r\   rs   ru   rx   r   r   r   r   r7   r   r   r"   r   r@   E   s    r@   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 )Nr8   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.r9   z%sParasiteAuxTransnameparasite_axes)	r   r;   ParasiteAxes
issubclassr	   r?   r<   r4   r@   )r>   parasite_axes_classr   r   r   $parasite_axes_auxtrans_class_factory   s   


r   c                       s   e Zd Z fddZ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 ZdddZdd ZdddZ		d fdd	Z  ZS )HostAxesBasec                    s   g | _ t j|i | d S rA   )r.   r   r   )r   argsr!   r"   r   r   r      s   zHostAxesBase.__init__rN   c                 C   s.   t |}|| ||}| j| | jj|_|S rA   )r   r.   appendremove_remove_method)r   trrE   r>   r   ax2r   r   r   get_aux_axes   s
   
zHostAxesBase.get_aux_axesNc                    s*   t   }| jD ]
}||| q|S rA   )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_positionr   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 rA   )r.   r%   r   r   r   r"   r   r   r%      s   

zHostAxesBase.clac                    s&   t  | | jD ]}|| q	d S rA   )r   r/   r.   r2   r"   r   r   r/      s   
zHostAxesBase.pickc                 C   n   |du r|   }t|}|| | dd}| j| | j|_| 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.
        NF)sharexr   rightT)lefttopbottom)_get_base_axesr?   r.   r   _remove_twinxr   axisset_visibler   r>   r   r   r   r   r   twinx     zHostAxesBase.twinxc                 C   4   | j | | jd d | jd jddd d S )Nr   TF
ticklabelslabelr.   r   r   r   toggler   r   r   r   r        zHostAxesBase._remove_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.
        NF)shareyr   r   T)r   r   r   )r   r?   r.   r   _remove_twinyr   r   r   r   r   r   r   twiny!  r   zHostAxesBase.twinyc                 C   r   )Nr   TFr   r   r   r   r   r   r   8  r   zHostAxesBase._remove_twinyc                    s   |du r   }t|}|du r| t dd}n| |dd} j|  jj|_ jd 	d |jd 	d |jd 	d  f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.
        NrN   )rE   rO   r   r   FT)r   r   c                    s4    j |   jd d  jd jddd d S )Nr   TFr   r   )hr-   r   r   r   X  r   z)HostAxesBase.twin.<locals>._remove_method)
r   r   rH   IdentityTransformr.   r   r   r   r   r   )r   	aux_transr>   parasite_axes_auxtrans_classr   r   r   r-   r   twin=  s&   

zHostAxesBase.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>c  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   h  s   $ )r.   r   r   r   union)r   r   r   r   bbsr"   r   r   r   `  s   zHostAxesBase.get_tightbboxrA   )NN)TN)r4   r5   r6   r   r   r   r   r   r%   r/   r   r   r   r   r   r   r7   r   r   r"   r   r      s    	


#r   c                    s@    d u rt jddd t  fdd}td j t fd|iS )Nr8   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.r9   c                    s    S rA   r   r-   r=   r   r   r   t  s   z/host_axes_class_factory.<locals>._get_base_axesz
%sHostAxesr   )r   r;   r   r<   r4   r   )r>   r   r   r=   r   host_axes_class_factoryk  s   
r   c                 C   s   t | }t|}|S rA   )r   r   )r>   host_axes_classsubplot_host_classr   r   r   host_subplot_class_factory|  s   r   )r>   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)r>   r   r   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   )r>   r   r   r!   r   host_subplot_classr   r   r   r   host_subplot  r   r   rA   )	functools
matplotlibr   r&   r   r   rH   matplotlib.axesr   matplotlib.transformsr   mpl_axesr   numpyr_   r	   	lru_cacher?   r   r@   r   ParasiteAxesAuxTransr   r   r   HostAxesSubplotHostr   r   r   r   r   r   <module>   s.    )o #