
    G8c\&                     $   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      Z ej$                  ed	      Z ee      Z G d
 d      Z ej$                  edd      Z ee      Z ee      Zd ZedddZedddZy)    )_apicbookN)subplot_class_factory)Bbox   )Axesc                        e Zd Zddd fdZ fdZ ej                  d      d        Z fdZ fdZ	d	 Z
d
 Zd Zd fd	Z xZS )ParasiteAxesBaseNviewlim_modec                    || _         || _        | j                  |       d|d<   t        |   |j
                  |j                  fi | y )NFframeon)_parent_axestransAuxset_viewlim_modesuper__init__figure	_position)selfparent_axesaux_transformr   kwargs	__class__s        G/usr/lib/python3/dist-packages/mpl_toolkits/axes_grid1/parasite_axes.pyr   zParasiteAxesBase.__init__   sJ    '%l+!y++[-B-BMfM    c                     t         |           t        j                  | j	                         d       | j
                  j                  | _        y )NF)visible)r   clearmartistsetpget_childrenr   
_get_linesr   r   s    r   r   zParasiteAxesBase.clear   s6    T&&(%8++66r   z3.5c                     g }g }| j                         D ]P  }|j                         st        |t        j                        r|j                  |       @|j                  |       R ||fS N)r"   get_visible
isinstancemimage	AxesImageappend)r   artistsimagesas       r   get_images_artistsz#ParasiteAxesBase.get_images_artists   sd    ""$ 	"A==?!V--.a q!	" wr   c                     t         |   |       | j                         D ]C  }t        |j                  d      s| |j                  j
                  v s3|j                  |       E y )N	parasites)r   pickr"   hasattrinaxesr1   r   
mouseeventr.   r   s      r   r2   zParasiteAxesBase.pick(   s[     	Z  ""$ 	#A
));7
 1 1 ; ;;z"	#r   c                 ~   | j                   | j                  j                  | _        | j                   | j                  j                  z   | _        t	        j
                  | j                  | j                        | _        t	        j
                  | j                  | j                        | _        y t        | %          y r&   )
r   r   	transAxes	transDatamtransformsblended_transform_factory_xaxis_transform_yaxis_transformr   _set_lim_and_transformsr$   s    r   r>   z(ParasiteAxesBase._set_lim_and_transforms6   s    ==$!..88DN!]]T->->-H-HHDN$/$I$I%0D!$/$I$I%0D! G+-r   c                 D    t        j                  g d|       || _        y )NNequal	transformmode)r   check_in_list_viewlim_mode)r   rD   s     r   r   z!ParasiteAxesBase.set_viewlim_modeA   s    7dC!r   c                     | j                   S r&   )rF   )r   s    r   get_viewlim_modez!ParasiteAxesBase.get_viewlim_modeE   s    !!!r   c                    | j                   j                  j                         }| j                         }|y |dk(  r&| j                  j                  j                  |       y |dk(  rM| j                  j                  j                  |j                  | j                  j                                      y t        j                  g d|       y )NrA   rB   r@   rC   )r   viewLimfrozenrH   axessettransformedr   invertedr   rE   )r   viewlimrD   s      r   _update_viewlimz ParasiteAxesBase._update_viewlimH   s    ##++224$$&<W_II!!'*[ II!!##DMM$:$:$<=? ;$Gr   c                 B    | j                          t        | 	          y r&   )rQ   r   apply_aspect)r   positionr   s     r   rS   zParasiteAxesBase.apply_aspectU   s    r   r&   )__name__
__module____qualname__r   r   r   
deprecatedr/   r2   r>   r   rH   rQ   rS   __classcell__r   s   @r   r
   r
   
   sZ    N!%N7
 T__U 
#	.""H r   r
   z
{}Parasitec                   ~     e Zd Z fdZddefdZ fdZ fdZ fdZddZ	dd	Z
dd
Zd Zd Z	 	 d fd	Z xZS )HostAxesBasec                 2    g | _         t        |   |i | y r&   )r1   r   r   )r   argsr   r   s      r   r   zHostAxesBase.__init__b   s    $)&)r   NrA   c                     t        |      } || ||      }| j                  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   )parasite_axes_class_factoryr1   r+   remove_remove_method)r   trr   
axes_classparasite_axes_classax2s         r   get_aux_axeszHostAxesBase.get_aux_axesf   sH     :*E!$F 	c"!^^22
r   c                    t        | j                        }| j                         }|r. || |      }| j                  |d       | j	                  |       n| j	                          | j                         }| j                  D ]<  }|j	                  |       | j                  j                  |j                                > t        | )  |       | j                  |d = y )Nactive)which)len	_childrenget_axes_locatorset_positionrS   get_positionr1   extendr"   r   draw)r   rendererorig_children_lenlocatorposrectaxr   s          r   rq   zHostAxesBase.drawz   s    /'')$)Cc2c"  ".. 	5BOOD!NN!!"//"34	5 	XNN,-.r   c                 d    | j                   D ]  }|j                           t        |           y r&   )r1   r   r   )r   rw   r   s     r   r   zHostAxesBase.clear   s(    .. 	BHHJ	r   c                 h    t         |   |       | j                  D ]  }|j                  |        y r&   )r   r2   r1   r5   s      r   r2   zHostAxesBase.pick   s0    Z   	AFF:	r   c                     | j                  ||       }| j                  d   j                  d       |j                  d   j                  d       |j                  d   j                  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   rd   rw   s      r   twinxzHostAxesBase.twinx   sd       D 9		'&&u-
$$T*
'(44U;	r   c                     | j                  ||       }| j                  d   j                  d       |j                  d   j                  d       |j                  d   j                  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.
        )shareyr~   FT)r}   r|   r   r   r   s      r   twinyzHostAxesBase.twiny   sc       D 9		%$$U+
""4(
)*66u=	r   c                    |t        j                         }| j                  ||d      }| j                  d   j	                  d       |j                  d   j	                  d       |j                  d   j	                  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.
        rB   )r   r   )r~   r|   FT)r}   r   )r:   IdentityTransformr   r   r   )r   	aux_transrd   rw   s       r   twinzHostAxesBase.twin   s     #557I  ik ! K		.!--e4
++D1
 !--e4	r   c                     || j                   } t        |      | fi |}| j                  j                  |       | j                  |_        |S )zy
        Helper for `.twinx`/`.twiny`/`.twin`.

        *kwargs* are forwarded to the parasite axes constructor.
        )_base_axes_classr`   r1   r+   _remove_any_twinrb   )r   rd   r   rw   s       r   r   zHostAxesBase._add_twin_axes   sQ     ..J4(4TDVDb! 11	r   c                 V   | j                   j                  |       ddg}|j                  r|j                  d       |j                  r|j                  d       | j                  t        |         j                  d       | j                  t        |         j                  dd       y )Nr~   r|   TF)
ticklabelslabel)r1   ra   _sharex_shareyr   tupler   toggle)r   rw   restores      r   r   zHostAxesBase._remove_any_twin   s    b!'"::NN5!::NN7#		%.!--d3		%.!((E(Gr   c                    g | j                   D cg c]  }|j                  ||       c}t        |   |||      }t        j                  |D cg c]#  }|j
                  dk7  s|j                  dk7  s"|% c}      S c c}w c c}w )N)call_axes_locator)r   bbox_extra_artistsr   )r1   get_tightbboxr   r   unionwidthheight)r   rr   r   r   rw   bbsbr   s          r   r   zHostAxesBase.get_tightbbox   s    J( x;LM (J G!(4E5G " IJ zzcKQWW\QXX]1KLL(
 Ls   B#B8Br&   )NN)NTN)rU   rV   rW   r   r   rg   rq   r   r2   r   r   r   r   r   r   rY   rZ   s   @r   r\   r\   a   sT    * #T (/&
 H >B)-M Mr   r\   z
{}HostAxesr   c                 2    t        |       }t        |      }|S r&   )host_axes_class_factoryr   )rd   host_axes_classsubplot_host_classs      r   host_subplot_class_factoryr      s    -j9O.?r   )rd   r   c                     ddl m} t        |       }||j                         } ||g|i |}|j	                  |       |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)rd   r   r^   r   pltr   rw   s          r   	host_axesr      sF     $-j9O~		1$	1&	1B
OOBIr   c                     ddl m} t        |       }||j                         } ||g|i |}|j	                  |       |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   add_subplot)rd   r   r^   r   r   host_subplot_classrw   s          r   host_subplotr     sI     $3J?~	F	4T	4V	4B
rIr   )
matplotlibr   r   matplotlib.artistartistr    matplotlib.imageimager)   matplotlib.transforms
transformsr:   matplotlib.axesr   r   mpl_axesr   r
   _make_class_factoryr`   ParasiteAxesr\   r   HostAxesSubplotHostr   r   r    r   r   <module>r      s    " # ! + 1 & M Md 8e77l$ *40AM AMH 4%33, 24 "4(#H- !%T , $( r   