3
$ßL]›3  ã               @   s^  d dl Zd dlZd dlmZ d dljZd dlj	Z	d dl
mZmZ dYdd„ZdZdd	„Zed
gdgd�dd„ ƒZedgdgd�dd„ ƒZedgdgd�dd„ ƒZedgd�dd„ ƒZedgddgd�dd„ ƒZedgdgd�dd „ ƒZd!d"„ Zed#gdgd�d$d%„ ƒZed&gdgd�d'd(„ ƒZed)gdgd�d*d+„ ƒZed,gdgd�d-d.„ ƒZed/gdgd�d0d1„ ƒZed2gdgd�d3d4„ ƒZed5gd6dgd�d7d8„ ƒZed9gdgd�d:d;„ ƒZed<gdgd�d=d>„ ƒZed?gdgd�d@dA„ ƒZedBgdgd�dCdD„ ƒZ dEdF„ Z!dGdH„ Z"dIdJ„ Z#dKdL„ Z$dMdN„ Z%dOdP„ Z&ej'j(dQƒej'j)dRdS�edTgdgdUdVdW�dXdT„ ƒƒƒZ*dS )[é    N)Úimage_comparison)ÚtickerÚrcParamsé   Fc             C   sb   | j ddgƒ | jdd� |sJ| jd|d� | jd|d� | jd|d� n| jd	ƒ | jd	ƒ d S )
Né   é   é   )Únbinszx-label)Úfontsizezy-labelÚTitleÚ )ÚplotZlocator_paramsÚ
set_xlabelÚ
set_ylabelÚ	set_titleZset_xticklabelsZset_yticklabels)Úaxr
   Únodec© r   úO/tmp/pip-install-edjban26/matplotlib/matplotlib/tests/test_constrainedlayout.pyÚexample_plot
   s    
r   c          	   C   s¬   d\}}t jtdd| |ƒtdd| |ƒf \}}d|d  |d  |d  t j|d  |d  ƒ }| j|||dddd	d
�}| jd|d� | jd|d� | jd|d� |S )Nç333333ã?r   r   g       @é   r   ZRdBu_rg      ð?T)ZcmapZvminZvmaxZ
rasterizedzx-label)r
   zy-labelr   )r   r   éýÿÿÿr   g      ð¿)ÚnpZmgridÚsliceÚexpÚ
pcolormeshr   r   r   )r   r
   ZdxZdyÚyÚxÚzÚpcmr   r   r   Úexample_pcolor   s    4r!   Zconstrained_layout1Zpng)Úbaseline_imagesÚ
extensionsc              C   s&   t jdd�} | jdƒ}t|dd� dS )z,Test constrained_layout for a single subplotT)Úconstrained_layoutéo   é   )r
   N)ÚpltÚfigureÚadd_subplotr   )Úfigr   r   r   r   Útest_constrained_layout1$   s    
r+   Zconstrained_layout2c              C   s4   t jdddd�\} }x|jD ]}t|dd� qW dS )z(Test constrained_layout for 2x2 subplotsr   T)r$   r&   )r
   N)r'   ÚsubplotsÚflatr   )r*   Úaxsr   r   r   r   Útest_constrained_layout2-   s    r/   Zconstrained_layout3c              C   s^   t jdddd�\} }xDt|jƒD ]6\}}t|dd�}|dkrBd}nd}| j|||d	� q W d
S )z3Test constrained_layout for colorbars with subplotsr   T)r$   r&   )r
   r   g{®Gáz´?g{®Gáz”?)r   ÚpadN)r'   r,   Ú	enumerater-   r!   Úcolorbar)r*   r.   Únnr   r    r0   r   r   r   Útest_constrained_layout36   s    r4   Zconstrained_layout4)r"   c              C   sF   t jdddd�\} }x|jD ]}t|dd�}qW | j||ddd� d	S )
z;Test constrained_layout for a single colorbar with subplotsr   T)r$   r&   )r
   g{®Gáz„?g333333ã?)r   r0   ÚshrinkN)r'   r,   r-   r!   r2   )r*   r.   r   r    r   r   r   Útest_constrained_layout4D   s    r6   Zconstrained_layout5gš™™™™™©?)r"   Ztolr#   c              C   sJ   t jdddd�\} }x|jD ]}t|dd�}qW | j||dddd	d
� dS )zZ
    Test constrained_layout for a single colorbar with subplots,
    colorbar bottom
    r   T)r$   r&   )r
   Fg{®Gáz„?g333333ã?Úbottom)r   Zuse_gridspecr0   r5   ÚlocationN)r'   r,   r-   r!   r2   )r*   r.   r   r    r   r   r   Útest_constrained_layout5M   s    r9   Zconstrained_layout6c           	   C   sÌ   t jdd�} | jdd| d�}|d jddƒ}|d jddƒ}g }x,|D ]$}| j|ƒ}||g7 }t|dd� qFW |jd	ƒ g }x,|D ]$}| j|ƒ}||g7 }t|dd�}q‚W | j||d
ddt	j
dd�d� dS )z,Test constrained_layout for nested gridspecsT)r$   r   r   )r(   r   r   )r
   zx-label
MultiLineg{®Gáz„?g®Gáz®ï?r7   r   )r	   )r   r0   r5   r8   ZticksN)r'   r(   Zadd_gridspecZsubgridspecr)   r   r   r!   r2   r   ZMaxNLocator)r*   ÚgsÚgslÚgsrÚaxslr   Zaxsrr    r   r   r   Útest_constrained_layout6\   s$    






r>   c              C   s†   t jtdd��n tjdd�} tjddƒ}tjdd|d ƒ}tjdd|d ƒ}g }x|D ]}| j|ƒ}qVW | j	| j
jƒ ƒ W dQ R X dS )	z2Test for proper warning if fig not set in GridSpeczPCalling figure.constrained_layout, but figure not setup to do constrained layout)ÚmatchT)r$   r   r   r   N)ÚpytestZwarnsÚUserWarningr'   r(   ÚgridspecÚGridSpecÚGridSpecFromSubplotSpecr)   ÚdrawÚcanvasZget_renderer)r*   r:   r;   r<   r=   r   r   r   r   Útest_constrained_layout7u   s    
rG   Zconstrained_layout8c              C   sî   t jddd�} tjdd| d�}g }xˆdD ]€}|dkr<dg}ndd	g}xb|D ]Z}| j|||f ƒ}||g7 }t|d
d�}|dkrˆ|jdƒ |dk rš|jdƒ |jdƒ qJW q(W | j|ddd…f ƒ}||g7 }t|d
d�}| j	||ddd� dS )z/Test for gridspecs that are not completely fullé
   r   T)Úfigsizer$   r   )r(   r   r   é   é	   )r
   r   r   Ng{®Gáz„?g333333ã?)r   r0   r5   )rH   r   )r   r   )
r'   r(   rB   rC   r)   r!   r   r   r   r2   )r*   r:   r.   ÚjZilistÚir   r    r   r   r   Útest_constrained_layout8„   s(    





rN   Zconstrained_layout9c              C   sv   t jdddddd�\} }x.|jD ]$}t|dd�}|jdƒ |jdƒ q W |jdƒ | j||d	d
d� | jddd� dS )z4Test for handling suptitle and for sharex and shareyr   TF)r$   ZsharexZshareyr&   )r
   r   g       @g{®Gáz„?g333333ã?)r   r0   r5   zTest Suptitleé   N)	r'   r,   r-   r!   r   r   Z
set_aspectr2   Úsuptitle)r*   r.   r   r    r   r   r   Útest_constrained_layout9    s    


rQ   Zconstrained_layout10c              C   sJ   t jdddd�\} }x"|jD ]}|jtjdƒdd� qW |jddd
� dS )z%Test for handling legend outside axisr   T)r$   r   zThis is a label)Úlabelzcenter leftçš™™™™™é?ç      à?)ÚlocZbbox_to_anchorN)rS   rT   )r'   r,   r-   r   r   ZarangeZlegend)r*   r.   r   r   r   r   Útest_constrained_layout10¯   s    rV   Zconstrained_layout11c              C   s¾   t jddd�} tjdd| d�}tjdd|d ƒ}tjdd|d ƒ}| j|d ƒ}t|d	d
� g }x,|D ]$}| j|ƒ}||g7 }t|d	d
�}qfW | j||ddd� | j|d ƒ}t|d	d
� dS )z#Test for multiple nested gridspecs TrH   r   )r$   rI   r   r   )r(   r   rK   )r
   g333333ã?g     €Q@)r   r5   ÚaspectN)rH   r   )	r'   r(   rB   rC   rD   r)   r   r!   r2   )r*   Úgs0r;   Úgsl0r   r.   r:   r    r   r   r   Útest_constrained_layout11¹   s    


rZ   Zconstrained_layout11ratc              C   sÌ   t jddd�} tjdd| ddgd	�}tjdd|d
 ƒ}tjdd|d ddgd�}| j|d ƒ}t|dd� g }x,|D ]$}| j|ƒ}||g7 }t|dd�}qtW | j||ddd� | j|d
 ƒ}t|dd� dS )z4Test for multiple nested gridspecs with width_ratiosTrH   r   )r$   rI   r   r   g      @g      ð?)r(   Zwidth_ratiosr   g       @)Zheight_ratiosrK   )r
   g333333ã?g     €Q@)r   r5   rW   N)rH   r   )	r'   r(   rB   rC   rD   r)   r   r!   r2   )r*   rX   r;   rY   r   r.   r:   r    r   r   r   Útest_constrained_layout11ratÍ   s    


r[   Zconstrained_layout12c              C   sÔ   t jdd�} tjdd| d�}| j|dd…df ƒ}| j|dd…df ƒ}t|d	d
� t|d	d
� | j|dd…df ƒ}t|dd� | j|dd…df ƒ}t|dd� | j|dd…df ƒ}t|dd� |jdƒ dS )z/Test that very unbalanced labeling still works.T)r$   é   r   )r(   Nr   r   r&   )r
   r   )r   rJ   zx-label)r'   r(   rB   rC   r)   r   r   )r*   rX   Úax1Úax2r   r   r   r   Útest_constrained_layout12â   s    r_   Zconstrained_layout13g{®Gáz”?c              C   sV   t jdddd�\} }x.|jD ]$}t|dd�}| j||dddd	� qW | jddd� dS )zTest that padding works.r   T)r$   r   )r
   g333333ã?g      4@g{®Gáz”?)r   r5   rW   r0   g      8@g      R@)Úw_padÚh_padNgUUUUUUÕ?gUUUUUUÕ?)r'   r,   r-   r!   r2   Úset_constrained_layout_pads)r*   r.   r   r    r   r   r   Útest_constrained_layout13ù   s
    rc   Zconstrained_layout14c              C   sZ   t jdddd�\} }x.|jD ]$}t|dd�}| j||dddd	� qW | jddddd� dS )zTest that padding works.r   T)r$   r   )r
   g333333ã?g      4@g{®Gáz”?)r   r5   rW   r0   g      @g      R@gš™™™™™É?)r`   ra   ZhspaceZwspaceNgUUUUUU¥?gUUUUUU¥?)r'   r,   r-   r!   r2   rb   )r*   r.   r   r    r   r   r   Útest_constrained_layout14  s    rd   Zconstrained_layout15c              C   s8   dt d< tjddƒ\} }x|jD ]}t|dd� q W dS )zTest that rcparams work.Tzfigure.constrained_layout.user   r   )r
   N)r   r'   r,   r-   r   )r*   r.   r   r   r   r   Útest_constrained_layout15  s    re   Zconstrained_layout16c              C   s2   t jdd�\} }t|dd� | jddddgƒ}dS )zTest ax.set_position.T)r$   r   )r
   gš™™™™™É?gš™™™™™Ù?N)r'   r,   r   Úadd_axes)r*   r   r^   r   r   r   Útest_constrained_layout16  s    rg   Zconstrained_layout17c              C   s”   t jdd�} tjdd| d�}| j|d	 ƒ}| j|ddd…f ƒ}| j|dd…dd…f ƒ}| j|dd…d
f ƒ}t|ƒ t|ƒ t|ƒ t|ƒ dS )zTest uneven gridspecsT)r$   r   )r(   r   r   Nr   )r   r   éÿÿÿÿ)r'   r(   rB   rC   r)   r   )r*   r:   r]   r^   Zax3Zax4r   r   r   Útest_constrained_layout17$  s    ri   c              C   sV   t jdd�\} }|jƒ }t|ƒ t|dd� | jjƒ  t|jƒ j|jƒ jkƒsRt	‚dS )z
Test twinxT)r$   r&   )r
   N)
r'   r,   Ztwinxr   rF   rE   ÚallÚget_positionÚextentsÚAssertionError)r*   r   r^   r   r   r   Útest_constrained_layout186  s    
rn   c              C   sj   t jdd�\} }|jƒ }t|ƒ t|dd� |jdƒ |jdƒ | jjƒ  t|jƒ j	|jƒ j	kƒsft
‚dS )z
Test twinyT)r$   r&   )r
   r   N)r'   r,   Ztwinyr   r   rF   rE   rj   rk   rl   rm   )r*   r   r^   r   r   r   Útest_constrained_layout19@  s    


ro   c              C   s\   t jdddƒ} t j| | dd…df ƒ}tjƒ }|jddddgƒ}|j| | |ƒ}|j|ƒ dS )z)Smoke test cl does not mess up added axesr   rJ   Nr   r   éûÿÿÿ)r   ZlinspaceÚhypotr'   r(   rf   r   r2   )ZgxÚimgr*   r   Zmeshr   r   r   Útest_constrained_layout20L  s    rs   c              C   sj   t jdd�\} }| jdƒ | jjƒ  tj|jƒ jƒ}| jdƒ | jjƒ  tj|jƒ jƒ}tj	j
||ƒ dS )z>#11035: repeated calls to suptitle should not alter the layoutT)r$   Z	Suptitle0Z	Suptitle1N)r'   r,   rP   rF   rE   r   Úcopyrk   rl   ÚtestingÚassert_allclose)r*   r   Úextents0Úextents1r   r   r   Útest_constrained_layout21W  s    



ry   c              C   sd   t jdd�\} }| jjƒ  tj|jƒ jƒ}| jddd� | jjƒ  tj|jƒ jƒ}tj	j
||ƒ dS )zC#11035: suptitle should not be include in CL if manually positionedT)r$   ZSuptitleg      à?)r   N)r'   r,   rF   rE   r   rt   rk   rl   rP   ru   rv   )r*   r   rw   rx   r   r   r   Útest_constrained_layout22f  s    

rz   c              C   s:   x4t dƒD ](} tjdddd�\}}|jdj| ƒƒ q
W dS )zu
    Comment in #11035: suptitle used to cause an exception when
    reusing a figure w/ CL with ``clear=True``.
    r   Z123T)Únumr$   Úclearz
Suptitle{}N)Úranger'   r,   rP   Úformat)rM   r*   r   r   r   r   Útest_constrained_layout23t  s    r   é   r   )ZrerunsÚtest_colorbar_locationTZmpl20)r"   r#   Zremove_textÚstylec              C   sî   t jdddd�\} }x*|jD ] }t|ƒ}|jdƒ |jdƒ qW | j||dd…df dd	� | j||ddd
…f ddd� | j||dd
d…f ddd� | j||ddd…f ddd� | j||d ddd� | j||dd…d
f ddd� dS )zY
    Test that colorbar handling is as expected for various complicated
    cases...
    rJ   r   T)r$   r   Nr   gš™™™™™Ù?)r   r5   r   g      à?r7   )r   r5   r8   r   r   ÚtopÚleftÚrightrh   éþÿÿÿ)r   r   )r'   r,   r-   r!   r   r   r2   )r*   r.   r   r    r   r   r   r�   ‚  s    

)r   F)r   )+Znumpyr   r@   Zmatplotlib.testing.decoratorsr   Zmatplotlib.pyplotZpyplotr'   Zmatplotlib.gridspecrB   Z
matplotlibr   r   r   r!   r+   r/   r4   r6   r9   r>   rG   rN   rQ   rV   rZ   r[   r_   rc   rd   re   rg   ri   rn   ro   rs   ry   rz   r   ÚmarkÚtimeoutZflakyr�   r   r   r   r   Ú<module>   sf   



		
	

