3
$ßL]a%  ã               @   s¾   d dl Z d dlZd dlmZmZ d dljZd dlm	Z	 d dl
mZmZ d dljZG dd„ deƒZi Ze jdƒddd„ƒZeƒ Zd	d
„ Zejjeje	ƒd� eje	jƒ ejjej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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|ƒdkrŠt|d tƒr,|d | _n\y$tt|d ƒƒ}tt|ƒ\}}}W n tk
rl   tdƒ‚Y nX t	||| j d�|d  | _nÒt|ƒdk�rN|\}}}t|ƒ}t|ƒ}t|t
ƒrþt|ƒdkrþdd„ |D ƒ}t	||| j d�|d d |d … | _nN|dk �s||| k�r.td	|| › d
|› �ƒ‚t	||| j d�t|ƒd  | _ntd|› �ƒ‚| jƒ  | jj| || jf|Ž | jjdk�r–d| _d| _nP| jjjd }|tjƒ  }tj| jj|| d�| _tj| j| jjd dd| d�| _dS )a  
        *fig* is a :class:`matplotlib.figure.Figure` instance.

        *args* is the tuple (*numRows*, *numCols*, *plotNum*), where
        the array of subplots in the figure has dimensions *numRows*,
        *numCols*, and where *plotNum* is the number of the subplot
        being created.  *plotNum* starts at 1 in the upper left
        corner and increases to the right.

        If *numRows* <= *numCols* <= *plotNum* < 10, *args* can be the
        decimal integer *numRows* * 100 + *numCols* * 10 + *plotNum*.
        é   r   z4Single argument to subplot must be a 3-digit integer)Úfigureé   é   c             S   s   g | ]}t |ƒ‘qS © )Úint)Ú.0Únr   r   úA/tmp/pip-install-edjban26/matplotlib/matplotlib/axes/_subplots.pyú
<listcomp>4   s    z(SubplotBase.__init__.<locals>.<listcomp>znum must be 1 <= num <= z, not z Illegal argument(s) to subplot: Nz.ax)ÚparentÚnameÚartistz.posT)r   r   ÚposZsubplotr   )r	   ÚlenÚ
isinstancer   Ú_subplotspecÚstrr   ÚmapÚ
ValueErrorr   ÚtupleÚupdate_paramsÚ_axes_classÚ__init__ÚfigboxÚ
_layoutboxÚ_poslayoutboxr   Ú	layoutboxZseq_idZ	LayoutBox)	ÚselfZfigÚargsÚkwargsÚsÚrowsÚcolsÚnumr   r   r   r   r      sR    
"

zSubplotBase.__init__c             C   s(   t dd„ t| ƒjD ƒƒ}t|f| jƒ fS )Nc             s   s(   | ] }t |tƒrt |tƒ r|V  qd S )N)Ú
issubclassr   r   )r   Úcr   r   r   ú	<genexpr>[   s    z)SubplotBase.__reduce__.<locals>.<genexpr>)ÚnextÚtypeÚ__mro__Ú$_picklable_subplot_class_constructorÚ__getstate__)r$   Ú
axes_classr   r   r   Ú
__reduce__X   s
    zSubplotBase.__reduce__c             C   s"   | j ƒ jƒ \}}}}|||d fS )z%get the subplot geometry, e.g., 2,2,3r   )Úget_subplotspecÚget_geometry)r$   r(   r)   Znum1Znum2r   r   r   r6   a   s    zSubplotBase.get_geometryc             C   s2   t ||| jd�|d  | _| jƒ  | j| jƒ dS )z2change 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numcolsr*   r   r   r   Úchange_geometryg   s    zSubplotBase.change_geometryc             C   s   | j S )z8get the SubplotSpec instance associated with the subplot)r   )r$   r   r   r   r5   n   s    zSubplotBase.get_subplotspecc             C   s
   || _ dS )z8set the SubplotSpec instance associated with the subplotN)r   )r$   Zsubplotspecr   r   r   Úset_subplotspecr   s    zSubplotBase.set_subplotspecc             C   s
   | j jƒ S )z5get the GridSpec instance associated with the subplot)r   Úget_gridspec)r$   r   r   r   r9   v   s    zSubplotBase.get_gridspecc             C   s,   | j ƒ j| jdd�\| _| _| _| _| _dS )z0update the subplot position from fig.subplotparsT)Z
return_allN)r5   Úget_positionr	   r    ÚrowNumÚcolNumÚnumRowsÚnumCols)r$   r   r   r   r   z   s    zSubplotBase.update_paramsc             C   s
   | j dkS )Nr   )r<   )r$   r   r   r   Úis_first_col�   s    zSubplotBase.is_first_colc             C   s
   | j dkS )Nr   )r;   )r$   r   r   r   Úis_first_row„   s    zSubplotBase.is_first_rowc             C   s   | j | jd kS )Nr   )r;   r=   )r$   r   r   r   Úis_last_row‡   s    zSubplotBase.is_last_rowc             C   s   | j | jd kS )Nr   )r<   r>   )r$   r   r   r   Úis_last_colŠ   s    zSubplotBase.is_last_colc             C   s”   | j ƒ }| jƒ }|sPx| jdd�D ]}|jdƒ q"W | jƒ jƒ jdƒ | jdƒ |s�x| jdd�D ]}|jdƒ qbW | jƒ jƒ jdƒ | j	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)
rA   r?   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jƒ ƒ}|jd|ƒ}| jj| jƒ f|žd|i|—Ž}||k	rz|j|ƒ | j	dƒ |j	dƒ | j
dk	r¾|j
dk	r¾|j
j| j
ƒ |jj| jƒ | jj| |ƒ |S )zN
        Make a twinx axes of self. This is used for twinx and twiny.
        ZsharexZshareyz$Twinned Axes may share only one axisrE   ZdatalimN)r   r   ÚuuidZuuid4Úpopr	   Zadd_subplotr5   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_axesN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r4   r6   r7   r5   r8   r9   r   r?   r@   rA   rB   rF   rK   r   r   r   r   r      s   F	r   c                sV   ˆ dkrt ‰ yt‡ fdd„tjƒ D ƒƒS  tk
rP   tdˆ j tˆ fdˆ iƒS X dS )aL  
    This makes 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.
    Nc             3   s    | ]}|j tˆ fkr|V  qd S )N)Ú	__bases__r   )r   Úcls)r3   r   r   r-   Ù   s    z(subplot_class_factory.<locals>.<genexpr>z	%sSubplotr   )r   r.   r   Ú__subclasses__ÚStopIterationr/   rL   )r3   r   )r3   r   Úsubplot_class_factoryÊ   s    	
rT   c             C   s   t | ƒ}|j|ƒS )z£
    This stub class exists to return the appropriate subplot class when called
    with an axes class. This is purely to allow pickling of Axes and Subplots.
    )rT   Ú__new__)r3   Zsubplot_classr   r   r   r1   å   s    r1   )ÚSubplot)N)Ú	functoolsrG   Z
matplotlibr   r   Zmatplotlib.artistr   ZmartistZmatplotlib.axes._axesr   Zmatplotlib.gridspecr   r   Zmatplotlib._layoutboxr!   r#   Úobjectr   Z_subplot_classesÚ	lru_cacherT   rV   r1   ZinterpdÚupdateZkwdocZdedent_interpdr   r   r   r   r   Ú<module>   s    

 =	