U
    \	¸aÆ  ã                   @   s®   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
mZ G dd„ dƒZi Ze  d¡ddd„ƒZeeƒZd	d
„ Zejje e¡d e ej¡ ejje e¡d dS )é    N)Ú_apiÚ	docstring)ÚAxes)ÚGridSpecÚSubplotSpecc                   @   s.  e Zd ZdZd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/d0„ Zd1S )2Ú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| |ddddgf|Ž |  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   é   N)Ú_axes_classÚ__init__Úset_subplotspecr   Z_from_subplot_args)ÚselfZfigÚargsÚkwargs© r   ú=/tmp/pip-unpacked-wheel-wjyw_3jo/matplotlib/axes/_subplots.pyr
      s    zSubplotBase.__init__c                 C   s(   t dd„ t| ƒjD ƒƒ}t|f|  ¡ fS )Nc                 s   s&   | ]}t |tƒrt |tƒs|V  qd S ©N)Ú
issubclassr   r   )Ú.0Úcr   r   r   Ú	<genexpr>*   s   
 
ÿz)SubplotBase.__reduce__.<locals>.<genexpr>)ÚnextÚtypeÚ__mro__Ú$_picklable_subplot_class_constructorÚ__getstate__)r   Ú
axes_classr   r   r   Ú
__reduce__(   s    ÿþzSubplotBase.__reduce__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rowsÚcolsZnum1Znum2r   r   r   r   1   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numcolsÚnumr   r   r   Úchange_geometry9   s    ÿÿzSubplotBase.change_geometryc                 C   s   | j S )z?Return the `.SubplotSpec` instance associated with the subplot.)r"   ©r   r   r   r   r   A   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   E   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)   J   s    zSubplotBase.get_gridspeczget_position()c                 C   s   |   ¡ S r   )r(   r'   r   r   r   r$   N   s    zSubplotBase.figboxzget_gridspec().nrowsc                 C   s
   |   ¡ jS r   )r)   Únrowsr'   r   r   r   ÚnumRowsT   s    zSubplotBase.numRowszget_gridspec().ncolsc                 C   s
   |   ¡ jS r   )r)   Úncolsr'   r   r   r   ÚnumColsY   s    zSubplotBase.numColsc                 C   s   dS )z=Update the subplot position from ``self.figure.subplotpars``.Nr   r'   r   r   r   r#   ^   s    zSubplotBase.update_paramsz#ax.get_subplotspec().is_first_row()c                 C   s   |   ¡ jjdkS ©Nr   )r   ÚrowspanÚstartr'   r   r   r   Úis_first_rowd   s    zSubplotBase.is_first_rowz"ax.get_subplotspec().is_last_row()c                 C   s   |   ¡ jj|  ¡ jkS r   )r   r/   Ústopr)   r*   r'   r   r   r   Úis_last_rowh   s    zSubplotBase.is_last_rowz#ax.get_subplotspec().is_first_col()c                 C   s   |   ¡ jjdkS r.   )r   Úcolspanr0   r'   r   r   r   Úis_first_coll   s    zSubplotBase.is_first_colz"ax.get_subplotspec().is_last_col()c                 C   s   |   ¡ jj|  ¡ jkS r   )r   r4   r2   r)   r,   r'   r   r   r   Úis_last_colp   s    zSubplotBase.is_last_colc                 C   s   |   ¡ }| ¡ }| ¡ }|sR| jddD ]}| d¡ q(| j ¡  d¡ |  d¡ |sŒ| jddD ]}| d¡ qb| j	 ¡  d¡ |  
d¡ dS )z±
        Only show "outer" labels and tick labels.

        x-labels are only kept for subplots on the last row; y-labels only for
        subplots on the first column.
        Zboth)ÚwhichFÚ N)r   r3   r5   Zget_xticklabelsZset_visibleZxaxisZget_offset_textZ
set_xlabelZget_yticklabelsZyaxisZ
set_ylabel)r   ÚssZlastrowZfirstcolÚlabelr   r   r   Úlabel_outert   s    
zSubplotBase.label_outerc                 O   sn   d|kr0d|kr0|d | k	r0|d | k	r0t dƒ‚| jj|  ¡ f|ž|Ž}|  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   r   Ú
deprecatedr   r&   r   r   r)   Úpropertyr$   r+   r-   r#   r1   r3   r5   r6   r;   r>   r   r   r   r   r   	   sL   	 þ

 ÿ




r   c                    s|   ˆ dkrt jddd t‰ zt‡ fdd„t ¡ D ƒƒW S  tk
rv   tˆ tƒrXˆ  Y S tdˆ j	 tˆ fdˆ iƒ Y S X dS )	aF  
    Make a new class that inherits from `.SubplotBase` and the
    given axes_class (which is assumed to be a subclass of `.axes.Axes`).
    This is perhaps a little bit roundabout to make a new class on
    the fly like this, but it means that a new Subplot class does
    not have to be created for every type of Axes.
    Nz3.3z§Support for passing None to subplot_class_factory is deprecated since %(since)s; explicitly pass the default Axes class instead. This will become an error %(removal)s.)Úmessagec                 3   s    | ]}|j tˆ fkr|V  qd S r   )Ú	__bases__r   )r   Úcls©r   r   r   r   ·   s    ÿz(subplot_class_factory.<locals>.<genexpr>z	%sSubplotr	   )
r   Zwarn_deprecatedr   r   r   Ú__subclasses__ÚStopIterationr   r   r?   rH   r   rH   r   Úsubplot_class_factory£   s    	 ÿ

þrK   c                 C   s   t | ƒ}| |¡S )zµ
    Stub factory that returns an empty instance of the appropriate subplot
    class when called with an axes class. This is purely to allow pickling of
    Axes and Subplots.
    )rK   Ú__new__)r   Zsubplot_classr   r   r   r   Æ   s    r   )Z
Axes_kwdoc)ZSubplot_kwdoc)N)Ú	functoolsZ
matplotlibr   r   Zmatplotlib.artistZartistZmartistZmatplotlib.axes._axesr   Zmatplotlib.gridspecr   r   r   Z_subplot_classesÚ	lru_cacherK   ZSubplotr   ZinterpdÚupdateZkwdocZdedent_interpdr
   r   r   r   r   Ú<module>   s    
