B
    Mô`ü2  ã               @   s  d dl Zd dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZmZ dYdd„ZdZdd	„Zed
gƒdd„ ƒZedgƒdd„ ƒZedgƒdd„ ƒZedgƒdd„ ƒZedgdd�dd„ ƒZedgƒdd„ ƒZdd„ Zed gƒd!d"„ ƒZed#gƒd$d%„ ƒZed&gƒd'd(„ ƒZed)gƒd*d+„ ƒZed,gƒd-d.„ ƒZed/gƒd0d1„ ƒZed2gd3d�d4d5„ ƒZed6gƒd7d8„ ƒZed9gƒd:d;„ ƒZed<gƒd=d>„ ƒZed?gƒd@dA„ ƒZ dBdC„ Z!dDdE„ Z"dFdG„ Z#dHdI„ Z$dJdK„ Z%dLdM„ Z&ej' (dN¡ej'j)dOdP�edQgdRdSdT�dUdV„ ƒƒƒZ*dWdX„ Z+dS )[é    N)Úimage_comparison)ÚtickerÚrcParamsé   Fc             C   sb   |   ddg¡ | jdd� |sJ| jd|d� | jd|d� | jd|d� n|  d	¡ |  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   úK/tmp/pip-unpacked-wheel-0c1wfn4v/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  |d  |d  ¡ }| j|||d d…d d…f d	d
ddd�}| jd|d� | jd|d� | jd|d� |S )N)g333333ã?g333333ã?éýÿÿÿr   r   g       @é   r   éÿÿÿÿZRdBu_rg      ð¿g      ð?T)ZcmapZvminZvmaxZ
rasterizedzx-label)r
   zy-labelr   )Ú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_layout1.pngc              C   s&   t jdd�} |  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_layout2.pngc              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_layout3.pngc              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    r.   r   r   r   Útest_constrained_layout33   s    r2   Zconstrained_layout4c              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   r.   ÚshrinkN)r%   r*   r+   r!   r0   )r(   r,   r   r    r   r   r   Útest_constrained_layout4@   s    r4   zconstrained_layout5.pnggš™™™™™©?)Ztolc              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_gridspecr.   r3   ÚlocationN)r%   r*   r+   r!   r0   )r(   r,   r   r    r   r   r   Útest_constrained_layout5I   s    r7   zconstrained_layout6.pngc           	   C   sÌ   t jdd�} | jdd| d�}|d  dd¡}|d  dd¡}g }x,|D ]$}|  |¡}||g7 }t|dd� qFW | d	¡ g }x,|D ]$}|  |¡}||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®ï?r5   r   )r	   )r   r.   r3   r6   ZticksN)r%   r&   Zadd_gridspecZsubgridspecr'   r   r   r!   r0   r   ZMaxNLocator)r(   ÚgsÚgslÚgsrZaxslr   Zaxsrr    r   r   r   Útest_constrained_layout6W   s$    






r;   c           	   C   s‚   t jtdd��j tjdd�} t dd¡}t dd|d ¡}t dd|d ¡}x|D ]}|  |¡ qRW |  	| 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(   r8   r9   r:   r   r   r   Útest_constrained_layout7o   s    
rD   zconstrained_layout8.pngc              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}|  |||f ¡}||g7 }t|dd�}|dkrˆ| d¡ |d	k rš| d¡ | d¡ qJW q(W |  |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   é   é	   )r
   r   r   Ng{®Gáz„?g333333ã?)r   r.   r3   )
r%   r&   r?   r@   r'   r!   r   r   r   r0   )r(   r8   r,   ÚjZilistÚir   r    r   r   r   Útest_constrained_layout8~   s(    





rK   zconstrained_layout9.pngc              C   sv   t jdddddd�\} }x.|jD ]$}t|dd�}| d¡ | d¡ q W | 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   r.   r3   zTest Suptitleé   N)	r%   r*   r+   r!   r   r   Z
set_aspectr0   Úsuptitle)r(   r,   r   r    r   r   r   Útest_constrained_layout9™   s    


rN   zconstrained_layout10.pngc              C   sJ   t jdddd�\} }x"|jD ]}|jt 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)gš™™™™™é?g      à?)ÚlocZbbox_to_anchorN)r%   r*   r+   r   r   ZarangeZlegend)r(   r,   r   r   r   r   Útest_constrained_layout10§   s    rQ   zconstrained_layout11.pngc              C   s¾   t jddd�} tjdd| d�}t dd|d ¡}t dd|d ¡}|  |d ¡}t|dd	� g }x,|D ]$}|  |¡}||g7 }t|dd	�}qfW | j||d
dd� |  |d ¡}t|dd	� dS )z"Test for multiple nested gridspecsT)é   r   )r"   rF   r   r   )r&   r   rH   )r
   g333333ã?g     €Q@)r   r3   ÚaspectN)	r%   r&   r?   r@   rA   r'   r   r!   r0   )r(   Úgs0r9   Úgsl0r   r,   r8   r    r   r   r   Útest_constrained_layout11°   s    


rV   zconstrained_layout11rat.pngc              C   sÌ   t jddd�} tjdd| ddgd�}t dd|d ¡}tjdd|d ddgd	�}|  |d ¡}t|d
d� g }x,|D ]$}|  |¡}||g7 }t|d
d�}qtW | j||ddd� |  |d ¡}t|d
d� dS )z4Test for multiple nested gridspecs with width_ratiosT)rE   r   )r"   rF   r   r   é   )r&   Zwidth_ratiosr   )Zheight_ratiosrH   )r
   g333333ã?g     €Q@)r   r3   rS   N)	r%   r&   r?   r@   rA   r'   r   r!   r0   )r(   rT   r9   rU   r   r,   r8   r    r   r   r   Útest_constrained_layout11ratÃ   s    


rX   zconstrained_layout12.pngc              C   sÔ   t jdd�} tjdd| d�}|  |dd…df ¡}|  |dd…df ¡}t|d	d
� t|d	d
� |  |dd…df ¡}t|dd� |  |dd…df ¡}t|dd� |  |dd…df ¡}t|dd� | d¡ dS )z/Test that very unbalanced labeling still works.T)r"   rW   r   )r&   Nr   r   r$   )r
   r   )r   rG   zx-label)r%   r&   r?   r@   r'   r   r   )r(   rT   Úax1Úax2r   r   r   r   Útest_constrained_layout12Ö   s    r[   zconstrained_layout13.pngg{®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   r3   rS   r.   gUUUUUUÕ?)Úw_padÚh_padN)r%   r*   r+   r!   r0   Úset_constrained_layout_pads)r(   r,   r   r    r   r   r   Útest_constrained_layout13ì   s
    r_   zconstrained_layout14.pngc              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   r3   rS   r.   gUUUUUU¥?gš™™™™™É?)r\   r]   ZhspaceZwspaceN)r%   r*   r+   r!   r0   r^   )r(   r,   r   r    r   r   r   Útest_constrained_layout14ö   s    r`   zconstrained_layout15.pngc              C   s8   dt d< t 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    ra   zconstrained_layout16.pngc              C   s2   t jdd�\} }t|dd� |  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   rZ   r   r   r   Útest_constrained_layout16  s    rc   zconstrained_layout17.pngc              C   s”   t jdd�} tjdd| d�}|  |d ¡}|  |ddd…f ¡}|  |dd…dd	…f ¡}|  |dd…d
f ¡}t|ƒ t|ƒ t|ƒ t|ƒ dS )zTest uneven gridspecsT)r"   r   )r&   )r   r   r   r   Nr   r   )r%   r&   r?   r@   r'   r   )r(   r8   rY   rZ   Zax3Zax4r   r   r   Útest_constrained_layout17  s    rd   c              C   sV   t jdd�\} }| ¡ }t|ƒ t|dd� | j ¡  t| ¡ j| ¡ jkƒsRt	‚dS )z
Test twinxT)r"   r$   )r
   N)
r%   r*   Ztwinxr   rC   rB   ÚallÚget_positionÚextentsÚAssertionError)r(   r   rZ   r   r   r   Útest_constrained_layout18$  s    
ri   c              C   sj   t jdd�\} }| ¡ }t|ƒ t|dd� | d¡ | d¡ | j ¡  t| ¡ j	| ¡ j	kƒsft
‚dS )z
Test twinyT)r"   r$   )r
   r   N)r%   r*   Ztwinyr   r   rC   rB   re   rf   rg   rh   )r(   r   rZ   r   r   r   Útest_constrained_layout19.  s    


rj   c              C   sl   t  ddd¡} t  | | dd…df ¡}t ¡ }| ddddg¡}| | | |dd…dd…f ¡}| |¡ dS )z)Smoke test cl does not mess up added axeséûÿÿÿr   rG   Nr   r   r   )r   ZlinspaceÚhypotr%   r&   rb   r   r0   )ZgxÚimgr(   r   Zmeshr   r   r   Útest_constrained_layout20:  s    rn   c              C   sj   t jdd�\} }|  d¡ | j ¡  t | ¡ j¡}|  d¡ | j ¡  t | ¡ j¡}tj	 
||¡ dS )z>#11035: repeated calls to suptitle should not alter the layoutT)r"   Z	Suptitle0Z	Suptitle1N)r%   r*   rM   rC   rB   r   Úcopyrf   rg   ÚtestingÚassert_allclose)r(   r   Úextents0Úextents1r   r   r   Útest_constrained_layout21E  s    



rt   c              C   sd   t jdd�\} }| j ¡  t | ¡ j¡}| jddd� | j ¡  t | ¡ j¡}tj	 
||¡ dS )zC#11035: suptitle should not be include in CL if manually positionedT)r"   ZSuptitleg      à?)r   N)r%   r*   rC   rB   r   ro   rf   rg   rM   rp   rq   )r(   r   rr   rs   r   r   r   Útest_constrained_layout22T  s    

ru   c              C   s:   x4t dƒD ](} tjdddd�\}}| d | ¡¡ 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*   rM   Úformat)rJ   r(   r   r   r   r   Útest_constrained_layout23b  s    rz   é   r   )Zrerunsztest_colorbar_location.pngTZmpl20)Zremove_textÚstylec              C   sî   t jdddd�\} }x*|jD ] }t|ƒ}| d¡ | 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...
    rG   r   T)r"   r   Nr   gš™™™™™Ù?)r   r3   r   r   g      à?r5   )r   r3   r6   r   éþÿÿÿr   Útop)r   r   ÚleftÚright)r%   r*   r+   r!   r   r   r0   )r(   r,   r   r    r   r   r   Útest_colorbar_locationp  s    

r�   c              C   s^   t jdddd�\} }|d  d¡ | j ¡  t |d  ¡ j¡}tj	j
|ddd	d
gdd� d S )Nr   T)r"   )r   r   F)r   r   g›çˆ|—R§?g…A™F“‹á?gÔÔ²µ¾HÞ?g³Ñ9?Åqï?gñhãˆµøä>)Zrtol)r%   r*   Zset_visiblerC   rB   r   ro   rf   rg   rp   rq   )r(   r,   rs   r   r   r   Útest_hidden_axes‡  s    
r‚   )r   F)r   ),Znumpyr   r=   Zmatplotlib.testing.decoratorsr   Zmatplotlib.pyplotZpyplotr%   Zmatplotlib.gridspecr?   Z
matplotlibr   r   r   r!   r)   r-   r2   r4   r7   r;   rD   rK   rN   rQ   rV   rX   r[   r_   r`   ra   rc   rd   ri   rj   rn   rt   ru   rz   ÚmarkÚtimeoutZflakyr�   r‚   r   r   r   r   Ú<module>   sH   

		
	

