o
    ¡:´a  ã                   @   s\   d dl Zd dl mZmZ d dlmZ d dlmZmZ G dd„ dƒZ	e 
e	dd¡ZeeƒZdS )	é    N)Ú_apiÚcbook)ÚAxes)ÚGridSpecÚSubplotSpecc                   @   s6  e Zd ZdZdd„ Zejdddddd	„ ƒZejdd
ddd„ ƒZdd„ Z	dd„ Z
dd„ Zejdddedd„ ƒƒZejdddedd„ ƒƒZejdddedd„ ƒƒZe d¡dd„ ƒZejdddd d!„ ƒZejdd"dd#d$„ ƒZejdd%dd&d'„ ƒZejdd(dd)d*„ ƒZd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3S )4ÚSubplotBasez¶
    Base class for subplots, which are :class:`Axes` instances with
    additional methods to facilitate generating and manipulating a set
    of :class:`Axes` within a figure.
    c                 O   s2   | j j| |g d¢fi |¤Ž |  t ||¡¡ dS )a›  
        Parameters
        ----------
        fig : `matplotlib.figure.Figure`

        *args : tuple (*nrows*, *ncols*, *index*) or int
            The array of subplots in the figure has dimensions ``(nrows,
            ncols)``, and *index* is the index of the subplot being created.
            *index* starts at 1 in the upper left corner and increases to the
            right.

            If *nrows*, *ncols*, and *index* are all single digit numbers, then
            *args* can be passed as a single 3-digit number (e.g. 234 for
            (2, 3, 4)).

        **kwargs
            Keyword arguments are passed to the Axes (sub)class constructor.
        )r   r   é   r   N)Ú_axes_classÚ__init__Úset_subplotspecr   Z_from_subplot_args)ÚselfZfigÚargsÚkwargs© r   ú;/usr/lib/python3/dist-packages/matplotlib/axes/_subplots.pyr
      s   zSubplotBase.__init__z3.4Úget_subplotspecz1(get_subplotspec returns a SubplotSpec instance.))ÚalternativeZaddendumc                 C   s"   |   ¡  ¡ \}}}}|||d fS )z*Get the subplot geometry, e.g., (2, 2, 3).r   )r   Úget_geometry)r   ZrowsZcolsZnum1Znum2r   r   r   r   &   s   zSubplotBase.get_geometryr   )r   c                 C   s2   t ||| jd|d  | _|  ¡  |  | j¡ dS )z;Change subplot geometry, e.g., from (1, 1, 1) to (2, 2, 3).)Úfigurer   N)r   r   Ú_subplotspecÚupdate_paramsZset_positionÚfigbox)r   ZnumrowsZnumcolsZnumr   r   r   Úchange_geometry.   s   ÿÿzSubplotBase.change_geometryc                 C   s   | j S )z?Return the `.SubplotSpec` instance associated with the subplot.)r   ©r   r   r   r   r   6   s   zSubplotBase.get_subplotspecc                 C   s   || _ |  | | j¡¡ dS )z=Set the `.SubplotSpec`. instance associated with the subplot.N)r   Z_set_positionÚget_positionr   )r   Zsubplotspecr   r   r   r   :   s   zSubplotBase.set_subplotspecc                 C   s
   | j  ¡ S )z<Return the `.GridSpec` instance associated with the subplot.)r   Úget_gridspecr   r   r   r   r   ?   s   
zSubplotBase.get_gridspeczget_position()c                 C   s   |   ¡ S ©N)r   r   r   r   r   r   C   s   zSubplotBase.figboxzget_gridspec().nrowsc                 C   ó
   |   ¡ jS r   )r   Únrowsr   r   r   r   ÚnumRowsI   ó   
zSubplotBase.numRowszget_gridspec().ncolsc                 C   r   r   )r   Úncolsr   r   r   r   ÚnumColsN   r    zSubplotBase.numColsc                 C   s   dS )z=Update the subplot position from ``self.figure.subplotpars``.Nr   r   r   r   r   r   S   s    zSubplotBase.update_paramsz#ax.get_subplotspec().is_first_row()c                 C   ó   |   ¡ jjdkS ©Nr   )r   ÚrowspanÚstartr   r   r   r   Úis_first_rowY   ó   zSubplotBase.is_first_rowz"ax.get_subplotspec().is_last_row()c                 C   ó   |   ¡ jj|  ¡ jkS r   )r   r%   Ústopr   r   r   r   r   r   Úis_last_row]   ó   zSubplotBase.is_last_rowz#ax.get_subplotspec().is_first_col()c                 C   r#   r$   )r   Úcolspanr&   r   r   r   r   Úis_first_cola   r(   zSubplotBase.is_first_colz"ax.get_subplotspec().is_last_col()c                 C   r)   r   )r   r-   r*   r   r!   r   r   r   r   Úis_last_cole   r,   zSubplotBase.is_last_colc                 C   s   | j dd | jdd dS )a  
        Only show "outer" labels and tick labels.

        x-labels are only kept for subplots on the last row (or first row, if
        labels are on the top side); y-labels only for subplots on the first
        column (or last column, if labels are on the right side).
        F)Úcheck_patchN)Ú_label_outer_xaxisÚ_label_outer_yaxisr   r   r   r   Úlabel_outeri   s   zSubplotBase.label_outerc                C   óÎ   |rt | jtjjƒsd S |  ¡ }| j ¡ }| ¡ s;|dkr"|  	d¡ | jj
ddd | jj ¡ d dkr;| jj d¡ | ¡ sc|dkrH|  	d¡ | jj
ddd | jj ¡ d d	kre| jj d¡ d S d S d S )
NÚtopÚ ÚbothF)ÚwhichZlabeltopr   Zbottom)r8   Zlabelbottomr   )Ú
isinstanceÚpatchÚmplÚpatchesÚ	Rectangler   ZxaxisÚget_label_positionr'   Z
set_xlabelÚset_tick_paramsÚ
offsetTextr   Úset_visibler+   ©r   r0   ÚssZlabel_positionr   r   r   r1   t   ó$   


ûzSubplotBase._label_outer_xaxisc                C   r4   )
NÚleftr6   r7   F)r8   Z	labelleftr   Úright)r8   Z
labelrightr   )r9   r:   r;   r<   r=   r   Zyaxisr>   r.   Z
set_ylabelr?   r@   r   rA   r/   rB   r   r   r   r2   ‡   rD   zSubplotBase._label_outer_yaxisc                 O   st   d|v rd|v r|d | ur|d | urt dƒ‚| jj|  ¡ g|¢R i |¤Ž}|  d¡ | d¡ | j | |¡ |S )z<Make a twinx axes of self. This is used for twinx and twiny.ZsharexZshareyz$Twinned Axes may share only one axisZdatalim)Ú
ValueErrorr   Zadd_subplotr   Zset_adjustableZ_twinned_axesÚjoin)r   r   r   Ztwinr   r   r   Ú_make_twin_axesš   s   

zSubplotBase._make_twin_axesN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   Z
deprecatedr   r   r   r   r   Úpropertyr   r   r"   r   r'   r+   r.   r/   r3   r1   r2   rI   r   r   r   r   r      sL    þ

ÿ




r   z	{}Subplotr	   )Z
matplotlibr;   r   r   Zmatplotlib.axes._axesr   Zmatplotlib.gridspecr   r   r   Z_make_class_factoryZsubplot_class_factoryZSubplotr   r   r   r   Ú<module>   s     "ÿ