a
    ìÝEb91  ã                   @   sF  d dl Z 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 d dl
mZ ddlmZ G dd„ dƒZe ed	¡ZeeƒZejd
dd�G dd„ dƒƒZejd
dd�e  d¡dd„ ƒƒZe ¡ � eeƒZW d  ƒ n1 sä0    Y  G dd„ dƒZe edd¡ZeeƒZeeƒZdd„ Z eddœdd„Z!eddœdd„Z"dS )é    N)Ú_apiÚcbook)Úsubplot_class_factory)ÚBboxé   )ÚAxesc                       s–   e Zd Zdddœ‡ fdd„Z‡ fdd„Ze d¡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 )NFZframeon)Ú_parent_axesÚtransAuxÚset_viewlim_modeÚsuperÚ__init__ÚfigureÚ	_position©ÚselfZparent_axesÚaux_transformr
   Úkwargs©Ú	__class__© úe/home/ja/django-apps/lartica_env/lib/python3.9/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ÚmartistZsetpÚget_childrenr   Z
_get_lines©r   r   r   r   r      s    
zParasiteAxesBase.claz3.5c                 C   sJ   g }g }|   ¡ D ]0}| ¡ sqt|tjƒr6| |¡ q| |¡ q||fS ©N)r   Zget_visibleÚ
isinstanceÚmimageZ	AxesImageÚappend)r   ZartistsZimagesÚar   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   ÚhasattrZinaxesr%   ©r   Z
mouseeventr#   r   r   r   r&   *   s    
ÿzParasiteAxesBase.pickc                    sX   | j d urJ| jj| _| j | jj | _t | j| j¡| _t | j| j¡| _n
tƒ  	¡  d S r   )
r   r   Ú	transAxesÚ	transDataÚmtransformsÚblended_transform_factoryÚ_xaxis_transformÚ_yaxis_transformr   Ú_set_lim_and_transformsr   r   r   r   r/   8   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   r5   r   r   r   r   C   s    z!ParasiteAxesBase.set_viewlim_modec                 C   s   | j S r   ©r8   r   r   r   r   Úget_viewlim_modeG   s    z!ParasiteAxesBase.get_viewlim_modeú3.4Úapply_aspect©Úalternativec                 C   s   | j S r   ©Ú_update_viewlimr   r   r   r   Úupdate_viewlimJ   s    zParasiteAxesBase.update_viewlimc                 C   sp   | j j ¡ }|  ¡ }|d u rnN|dkr6| jj |¡ n6|dkrZ| jj | | j ¡ ¡¡ nt	j
g d¢|d� d S ©Nr2   r3   r1   r4   ©r   ZviewLimÚfrozenr;   ZaxesÚsetZtransformedr   Úinvertedr   r7   ©r   Zviewlimr5   r   r   r   rA   N   s    ÿz ParasiteAxesBase._update_viewlimc                    s   |   ¡  tƒ  ¡  d S r   ©rA   r   r=   ©r   Úpositionr   r   r   r=   [   s    zParasiteAxesBase.apply_aspect)N)N)Ú__name__Ú
__module__Ú__qualname__r   r   r   Ú
deprecatedr$   r&   r/   r   r;   rB   rA   r=   Ú__classcell__r   r   r   r   r      s   ÿ

r   z
{}Parasiter<   r>   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   i   s
    ÿÿz!ParasiteAxesAuxTransBase.__init__c                 C   sB   | j j| _| j| j j | _t | j| j¡| _t | j| j¡| _d S r   )r   r)   r   r*   r+   r,   r-   r.   r   r   r   r   r/   o   s    
ÿÿz0ParasiteAxesAuxTransBase._set_lim_and_transformsc                 C   s   t jg d¢|d� || _d S r0   r6   r9   r   r   r   r   w   s    z)ParasiteAxesAuxTransBase.set_viewlim_modec                 C   s   | j S r   r:   r   r   r   r   r;   {   s    z)ParasiteAxesAuxTransBase.get_viewlim_moder<   r=   r>   c                 C   s   |   ¡ S r   r@   r   r   r   r   rB   ~   s    z'ParasiteAxesAuxTransBase.update_viewlimc                 C   sp   | j j ¡ }|  ¡ }|d u rnN|dkr6| jj |¡ n6|dkrZ| jj | | j ¡ ¡¡ nt	j
g d¢|d� d S rC   rD   rH   r   r   r   rA   ‚   s    ÿz(ParasiteAxesAuxTransBase._update_viewlimc                    s   |   ¡  tƒ  ¡  d S r   rI   rJ   r   r   r   r=   �   s    z%ParasiteAxesAuxTransBase.apply_aspect)N)N)rL   rM   rN   r   r/   r   r;   r   rO   rB   rA   r=   rP   r   r   r   r   rQ   g   s   
rQ   Úparasite_axes_class_factoryc                 C   s2   t | tƒst| ƒ}n| }td|j t|fddiƒS )Nz%sParasiteAuxTransÚnameZparasite_axes)Ú
issubclassr   rR   ÚtyperL   rQ   )Ú
axes_classÚparasite_axes_classr   r   r   Ú$parasite_axes_auxtrans_class_factory”   s    


þrX   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 r   )r%   r   r   )r   Úargsr   r   r   r   r   ¦   s    zHostAxesBase.__init__Nr2   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	   )rR   r%   r"   ÚremoveÚ_remove_method)r   Útrr
   rV   rW   Zax2r   r   r   Úget_aux_axesª   s
    
zHostAxesBase.get_aux_axesc                    s*   t ƒ  ¡ }| jD ]}| | |¡¡ q|S r   )r   Ú_get_legend_handlesr%   Úextend)r   Zlegend_handler_mapZall_handlesÚaxr   r   r   r_   ¾   s    

z HostAxesBase._get_legend_handlesc                    s�   t | jƒ}|  ¡ }|r:|| |ƒ}| j|dd� |  |¡ n|  ¡  |  ¡ }| jD ]}| |¡ | j | ¡ ¡ qPt	ƒ  
|¡ | jd |… | _d S )NÚactive)Úwhich)ÚlenÚ	_childrenZget_axes_locatorZset_positionr=   Úget_positionr%   r`   r   r   Údraw)r   ÚrendererZorig_children_lenÚlocatorÚposZrectra   r   r   r   rg   Ä   s    



zHostAxesBase.drawc                    s"   | j D ]}| ¡  qtƒ  ¡  d S r   )r%   r   r   )r   ra   r   r   r   r   ×   s    

zHostAxesBase.clac                    s&   t ƒ  |¡ | jD ]}| |¡ qd S r   )r   r&   r%   r(   r   r   r   r&   Ü   s    
zHostAxesBase.pickc                 C   sB   | 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   rV   ra   r   r   r   Útwinxã   s
    zHostAxesBase.twinxc                 C   sB   | j || d�}| jd  d¡ |jd  d¡ |jd  d¡ |S )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shareyrm   FT)rl   rk   rn   ro   rs   r   r   r   Útwinyð   s
    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.
        Nr3   )r   r
   )rm   rk   FT)rl   rn   )r+   ZIdentityTransformrp   rq   rr   )r   Z	aux_transrV   ra   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)Ú_base_axes_classrR   r%   r"   Ú_remove_any_twinr\   )r   rV   r   ra   r   r   r   rp     s    zHostAxesBase._add_twin_axesc                 C   sd   | j  |¡ ddg}|jr$| d¡ |jr4| d¡ | jt|ƒ  d¡ | jt|ƒ jddd� d S )Nrm   rk   TF)Z
ticklabelsÚlabel)r%   r[   Z_sharexZ_shareyrq   Útuplerr   Útoggle)r   ra   Úrestorer   r   r   rx     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)Ú.0ra   ©r}   rh   r   r   Ú
<listcomp>'  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�   ,  ó    )r%   r   r~   r   Úunion)r   rh   r}   r‚   Zbbsr   r€   r   r~   $  s    ÿÿþýzHostAxesBase.get_tightbbox)N)N)N)NN)TN)rL   rM   rN   r   r   r^   r_   rg   r   r&   rt   ru   rv   rp   rx   r~   rP   r   r   r   r   rY   ¥   s   



  ÿrY   z
{}HostAxesrw   c                 C   s   t | ƒ}t|ƒ}|S r   )Úhost_axes_class_factoryr   )rV   Úhost_axes_classZsubplot_host_classr   r   r   Úhost_subplot_class_factory5  s    rŠ   )rV   r   c                 O   sP   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ˆ   ÚgcfZadd_axesÚdraw_if_interactive)rV   r   rZ   r   Úpltr‰   ra   r   r   r   Ú	host_axes;  s    
r�   c                 O   sP   ddl m} t| ƒ}|du r$| ¡ }||g|¢R i |¤Ž}| |¡ | ¡  |S )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�   Zadd_subplotrŽ   )rV   r   rZ   r   r�   Zhost_subplot_classra   r   r   r   Úhost_subplotR  s    
r‘   )#Ú	functoolsZ
matplotlibr   r   Zmatplotlib.artistZartistr   Zmatplotlib.imageÚimager!   Zmatplotlib.transformsZ
transformsr+   Zmatplotlib.axesr   r   Zmpl_axesr   r   Z_make_class_factoryrR   ZParasiteAxesrO   rQ   Ú	lru_cacherX   Z'suppress_matplotlib_deprecation_warningZParasiteAxesAuxTransrY   rˆ   ZHostAxesZSubplotHostrŠ   r�   r‘   r   r   r   r   Ú<module>   s:   Vÿ,
& ÿ