B
    Mô`º%  ã               @   sÂ   d dl Z 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 d dl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)ÚcbookÚ	docstring)ÚAxes)ÚGridSpecÚSubplotSpecc               @   s¼   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Z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dd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(S ))Ú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   s    || _ t ||¡| _|  ¡  | jj| || jf|Ž | jjdkrLd| _d| _	nP| jjj
d }|t ¡  }tj| jj|| d�| _tj| j| jj
d dd| d�| _	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.
        Nz.ax)ÚparentÚnameÚartistz.posT)r   r	   ÚposZsubplotr
   )Úfigurer   Z_from_subplot_argsÚ_subplotspecÚupdate_paramsÚ_axes_classÚ__init__ÚfigboxÚ
_layoutboxÚ_poslayoutboxr	   Ú	layoutboxZseq_idZ	LayoutBox)ÚselfZfigÚargsÚkwargsr	   © r   ú=/tmp/pip-unpacked-wheel-0c1wfn4v/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__c             C   s"   |   ¡  ¡ \}}}}|||d fS )z*Get the subplot geometry, e.g., (2, 2, 3).é   )Úget_subplotspecÚget_geometry)r   ZrowsÚcolsZnum1Znum2r   r   r   r'   F   s    zSubplotBase.get_geometryc             C   s2   t ||| jd�|d  | _|  ¡  |  | j¡ dS )z;Change subplot geometry, e.g., from (1, 1, 1) to (2, 2, 3).)r   r%   N)r   r   r   r   Zset_positionr   )r   ZnumrowsZnumcolsÚnumr   r   r   Úchange_geometryL   s    zSubplotBase.change_geometryc             C   s   | j S )z?Return the `.SubplotSpec` instance associated with the subplot.)r   )r   r   r   r   r&   S   s    zSubplotBase.get_subplotspecc             C   s
   || _ dS )z=Set the `.SubplotSpec`. instance associated with the subplot.N)r   )r   Zsubplotspecr   r   r   Úset_subplotspecW   s    zSubplotBase.set_subplotspecc             C   s
   | j  ¡ S )z<Return the `.GridSpec` instance associated with the subplot.)r   Úget_gridspec)r   r   r   r   r,   [   s    zSubplotBase.get_gridspecc             C   s(   |   ¡ j| jdd�\| _}}| _| _dS )z=Update the subplot position from ``self.figure.subplotpars``.T)Z
return_allN)r&   Úget_positionr   r   ZnumRowsZnumCols)r   Ú_r   r   r   r   _   s    zSubplotBase.update_paramsz3.2z"ax.get_subplotspec().rowspan.start)Úalternativec             C   s   |   ¡ jjS )N)r&   ÚrowspanÚstart)r   r   r   r   ÚrowNume   s    zSubplotBase.rowNumz"ax.get_subplotspec().colspan.startc             C   s   |   ¡ jjS )N)r&   Úcolspanr1   )r   r   r   r   ÚcolNumj   s    zSubplotBase.colNumc             C   s   |   ¡ jjdkS )Nr   )r&   r0   r1   )r   r   r   r   Úis_first_rowo   s    zSubplotBase.is_first_rowc             C   s   |   ¡ jj|  ¡ jkS )N)r&   r0   Ústopr,   Znrows)r   r   r   r   Úis_last_rowr   s    zSubplotBase.is_last_rowc             C   s   |   ¡ jjdkS )Nr   )r&   r3   r1   )r   r   r   r   Úis_first_colu   s    zSubplotBase.is_first_colc             C   s   |   ¡ jj|  ¡ jkS )N)r&   r3   r6   r,   Zncols)r   r   r   r   Úis_last_colx   s    zSubplotBase.is_last_colc             C   s”   |   ¡ }|  ¡ }|sPx| jdd�D ]}| d¡ q"W |  ¡  ¡  d¡ |  d¡ |s�x| jdd�D ]}| d¡ qbW |  ¡  ¡  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)
r7   r8   Zget_xticklabelsZset_visibleZ	get_xaxisZget_offset_textZ
set_xlabelZget_yticklabelsZ	get_yaxisZ
set_ylabel)r   ZlastrowZfirstcolÚlabelr   r   r   Úlabel_outer{   s    
zSubplotBase.label_outerc             O   sÐ   d|kr0d|kr0|d | k	r0|d | k	r0t dƒ‚tt ¡ ƒ}| d|¡}| jj|  ¡ f|žd|i|—Ž}||k	rz| |¡ |  	d¡ | 	d¡ | j
dk	r¾|j
dk	r¾|j
 | j
¡ |j | j¡ | 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 axisr<   ZdatalimN)Ú
ValueErrorÚstrÚuuidZuuid4Úpopr   Zadd_subplotr&   Z	set_labelZset_adjustabler   Zconstrain_samer   Z_twinned_axesÚjoin)r   r   r   ÚsentinelZ
real_labelZtwinr   r   r   Ú_make_twin_axes�   s     


zSubplotBase._make_twin_axesc             C   sÈ   g }|   ¡ r |d|   ¡ ›�g7 }g }x0dD ](}| j|d�}|r*| |›d|›�¡ q*W |rr|dd |¡ d g7 }|  ¡ rŽ|d|  ¡ ›�g7 }|  ¡ rª|d	|  ¡ ›�g7 }d
| jj› d�d |¡ d S )Nzlabel=)ÚleftÚcenterÚright)Úlocú:ztitle={ú,Ú}zxlabel=zylabel=ú<z, ú>)Z	get_labelZ	get_titleÚappendrB   Z
get_xlabelZ
get_ylabelÚ	__class__Ú__name__)r   ÚfieldsÚtitlesÚkÚtitler   r   r   Ú__repr__©   s    
zSubplotBase.__repr__N)rP   Ú
__module__Ú__qualname__Ú__doc__r   r$   r'   r*   r&   r+   r,   r   r   Ú
deprecatedÚpropertyr2   r4   r5   r7   r8   r9   r=   rD   rU   r   r   r   r   r      s(   +	r   c                sd   ˆ dkrt jddd� t‰ yt‡ fdd„t ¡ D ƒƒS  tk
r^   tdˆ j tˆ fdˆ iƒ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 )N)Ú	__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   rP   )r#   r   )r#   r   Úsubplot_class_factoryÇ   s    	

r`   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.
    )r`   Ú__new__)r#   Zsubplot_classr   r   r   r!   å   s    r!   )ÚSubplot)N)Ú	functoolsr@   Z
matplotlibr   r   Zmatplotlib.artistr
   ZmartistZmatplotlib.axes._axesr   Zmatplotlib.gridspecr   r   Zmatplotlib._layoutboxr   r   r   Z_subplot_classesÚ	lru_cacher`   rb   r!   ZinterpdÚupdateZkwdocZdedent_interpdr   r   r   r   r   Ú<module>   s     :
