B
    Mô`C(  ã               @   s   d dl Z d dlZd dlmZ d dlZd dlZd dlm	Z	 d dl
mZ d dlmZmZ d dlmZ dGdd„Ze	d	gd
d�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e	dgƒdd„ ƒZe	dgd
d�d d!„ ƒZe	d"gƒd#d$„ ƒZe	d%gƒd&d'„ ƒZd(d)„ ZdHd-d.„Ze	d/d0gƒd1d2„ ƒZd3d4„ Zej  !d5d6d7g¡d8d9„ ƒZ"d:d;„ Z#d<d=„ Z$d>d?„ Z%d@dA„ Z&dBdC„ Z'ej  (dD¡dEdF„ ƒZ)dS )Ié    N)Úassert_array_equal)Úimage_comparison)ÚAnchoredOffsetboxÚDrawingArea)Ú	Rectangleé   c             C   sH   |   ddg¡ | jdd� | jd|d� | jd|d� | jd|d� d S )	Né   é   é   )Únbinszx-label)Úfontsizezy-labelZTitle)ÚplotÚlocator_paramsÚ
set_xlabelÚ
set_ylabelÚ	set_title)Úaxr   © r   úE/tmp/pip-unpacked-wheel-0c1wfn4v/matplotlib/tests/test_tightlayout.pyÚexample_plot   s
    r   Ztight_layout1gffffffþ?)Ztolc              C   s$   t  ¡ \} }t|dd� t  ¡  dS )z'Test tight_layout for a single subplot.é   )r   N)ÚpltÚsubplotsr   Útight_layout)Úfigr   r   r   r   Útest_tight_layout1   s    r   Ztight_layout2c              C   sJ   t jddd�\} \\}}\}}t|ƒ t|ƒ t|ƒ t|ƒ t  ¡  dS )z(Test tight_layout for multiple subplots.r	   )ZnrowsZncolsN)r   r   r   r   )r   Úax1Úax2Úax3Úax4r   r   r   Útest_tight_layout2   s    r    Ztight_layout3c              C   sB   t  d¡} t  d¡}t  d¡}t| ƒ t|ƒ t|ƒ t  ¡  dS )z(Test tight_layout for multiple subplots.éÝ   éß   éz   N)r   Úsubplotr   r   )r   r   r   r   r   r   Útest_tight_layout3)   s    


r%   Ztight_layout4)z2.5.5z2.6.1)Zfreetype_versionc              C   sj   t  dd¡} t jdddd�}t jddddd�}t jdddd	�}t| ƒ t|ƒ t|ƒ t|ƒ t  ¡  d
S )z#Test tight_layout for subplot2grid.)r
   r
   )r   r   )r   r   r	   )Úcolspan)r   r   )r&   Úrowspan)r   r	   )r'   N)r   Úsubplot2gridr   r   )r   r   r   r   r   r   r   Útest_tight_layout45   s    r)   Ztight_layout5c              C   s4   t  d¡} t d¡ d¡}| j|dd� t  ¡  dS )zTest tight_layout for image.éo   éd   )é
   r,   Únone)ÚinterpolationN)r   r$   ÚnpZarangeZreshapeZimshowr   )r   Zarrr   r   r   Útest_tight_layout5C   s    
r0   Ztight_layout6c        	   	   C   sX  t  ¡ ��D t  dt¡ t ¡ } tj dd¡}|  	|d ¡}|  	|d ¡}t
|ƒ t
|ƒ |j| ddddgd� tj dd¡}x2|D ]*}|  	|¡}t
|ƒ | d¡ | d¡ q„W |jd	d
d� |j| ddddgdd� t|j|jƒ}t|j|jƒ}|j| dd||j  dd|j|  gd� |j| dd||j  dd|j|  gdd� W dQ R X dS )zTest tight_layout for gridspec.Úignorer	   r   r   g      à?)Úrectr
   Ú zx-labelr   )r   gÍÌÌÌÌÌÜ?)r2   Zh_padN)ÚwarningsÚcatch_warningsÚsimplefilterÚUserWarningr   ÚfigureÚmplZgridspecZGridSpecÚadd_subplotr   r   r   r   ÚminÚtopÚmaxÚbottom)	r   Zgs1r   r   Zgs2Ússr   r<   r>   r   r   r   Útest_tight_layout6L   s0    


r@   Ztight_layout7c              C   sr   d} t  ¡ \}}| ddg¡ |jdd� |jd| d� |jd| d� |jd	d
| d� |jdd| d� t  ¡  d S )Nr   r   r	   r
   )r   zx-label)r   zy-labelz
Left TitleÚleft)Úlocr   zRight TitleÚright)r   r   r   r   r   r   r   r   )r   r   r   r   r   r   Útest_tight_layout7v   s    rD   Ztight_layout8c              C   s0   t  ¡ } |  ddi¡ |  d¡}t|dd� dS )z#Test automatic use of tight_layout.Úpadgš™™™™™¹?r*   r   )r   N)r   r8   Zset_tight_layoutr:   r   )r   r   r   r   r   Útest_tight_layout8„   s    
rF   Ztight_layout9c              C   s.   t  dd¡\} }|d d  d¡ t  ¡  d S )Nr	   r   F)r   r   Úset_visibler   )ÚfZaxarrr   r   r   Útest_tight_layout9�   s    rI   c              C   s�  t  ¡ } |  d¡}|jjdddd� |jjdddd� |jjdddddd	� |jjdddddd	� |jjd
gdd� |jjd
gdd� |  d¡}|jjdddd� |jjdddd� |  d¡}|jjdddd� |jjdddd� |  d¡}|jjdddd� |jjdddd� t  ¡  ddgddggddgddggddgddggddgddggg}x6t| j	ƒD ](\}}t
t | ¡  ¡ d¡|| ƒ �q`W dS )z#Test automatic use of tight_layout.r!   Úouté   r
   )ÚtickdirÚlengthÚwidthé    TÚminor)rL   rM   rN   Ztick1OnÚwhichr   )rP   éÞ   Úinr"   Zinoutéà   g²�ï§ÆK·?g�•C‹lã?gƒÀÊ¡E¶Û?gB`åÐ"Ûí?gºI+‡â?g/Ý$�í?gìQ¸…ëÁ?gmçû©ñÒÝ?N)r   r8   r:   ZxaxisZset_tick_paramsZyaxisZ	set_ticksr   Ú	enumerateZaxesr   r/   ÚroundÚget_positionZ
get_points)r   r   ZansÚnnr   r   r   Útest_outward_ticks–   s6    



rY   r,   çš™™™™™¹?Úblackc          
   C   s´   |d|  }}| | f| df| |f|dfd|f||fd| f|| fd| fg	}xX|D ]P}t ||ƒ}td|||dddd�}	| |	¡ td|d	d|| jd	d
�}
|  |
¡ q\W |
S )z&
    Surround ax with OffsetBoxes
    r   g      à?)r   r   ÚNoner   F)rN   ÚheightZ	facecolorZ	edgecolorZ	linewidthZantialiasedÚcenterg        )rB   ÚchildrE   ZframeonZbbox_to_anchorZbbox_transformZ	borderpad)r   r   Z
add_artistr   Z	transAxes)r   ÚsizeÚmarginÚcolorÚmÚmpZanchor_pointsZpointÚdaZ
backgroundZanchored_boxr   r   r   Úadd_offsetboxes·   s.    


rf   Ztight_layout_offsetboxes1Ztight_layout_offsetboxes2c                 s–   d ‰‰ddddg‰ ddg ‰‰‡ ‡‡‡‡fdd	„} | ƒ }t  ¡  | ƒ }x@|ˆd d ˆ… D ]*}x$| ¡ D ]}t|tƒrj| d
¡ qjW q\W t  ¡  d S )Nr	   ZredZblueZgreenZyellowr   r   c                 sP   t  ˆˆ¡\} }|j}x4t|ˆ ƒD ]&\}}|jˆˆ|d� t|d|d� q"W |S )N)rb   é   )r   r   ZflatÚzipr   rf   )Ú_Úaxsr   rb   )ÚcolorsÚcolsÚrowsÚxÚyr   r   Ú	_subplotsç   s    z0test_tight_layout_offsetboxes.<locals>._subplotsF)r   r   Zget_childrenÚ
isinstancer   rG   )rp   rj   r   r_   r   )rk   rl   rm   rn   ro   r   Útest_tight_layout_offsetboxesÕ   s    	
rr   c              C   s   t  ¡ } |  ¡  dS )zETest that tight layout doesn't cause an error when there are no axes.N)r   Zgcfr   )r   r   r   r   Útest_empty_layoutý   s    rs   ÚlabelZxlabelZylabelc             C   s$   t jdd�\}}|jf | diŽ dS )z8Test that no warning emitted when xlabel/ylabel too big.)r
   r	   )ÚfigsizeZdaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaN)r   r   Úset)rt   r   r   r   r   r   Útest_verybig_decorators  s    rw   c              C   s4   t jdddd�\} }|d  d¡ |d  d¡ dS )	z+Test that doesn't warn when xlabel too big.r   r	   )r
   r	   )ru   r   ZaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaZbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbN)r   r   r   )r   rj   r   r   r   Útest_big_decorators_horizontal
  s    rx   c              C   s4   t jdddd�\} }|d  d¡ |d  d¡ dS )	z+Test that doesn't warn when ylabel too big.r	   r   )r
   r	   )ru   r   ZaaaaaaaaaaaaaaaaaaaaZbbbbbbbbbbbbbbbbbbbbN)r   r   r   )r   rj   r   r   r   Útest_big_decorators_vertical  s    ry   c            	   C   s@   t  dd¡ t jddddd� t t¡� t  ¡  W d Q R X d S )N)é   é   )r   r   )r{   r{   )r   r
   r
   r{   )r&   r'   )r   r(   ÚpytestÚwarnsr7   r   r   r   r   r   Útest_badsubplotgrid  s    r~   c           	   C   s¨   t jdd�\} }| ddg¡ | ddg¡ |jdddd� | ¡ }t t¡�& t  	¡  | ¡ }|j
|j
kspt‚W d Q R X t t¡� t j	ddd	d	gd
� W d Q R X d S )NT)r   r   r   zBIG LONG STRING)g      ô?r	   )g      %@g      ü?)ZxyZxytextgš™™™™™é?)r2   )r   r   Zset_xlimZset_ylimZannotaterW   r|   r}   r7   r   rN   ÚAssertionError)r   r   Úp1Úp2r   r   r   Útest_collapsed!  s    r‚   c              C   sJ   t jdd�\} }|  d¡}| d¡}| j ¡  | ¡ j| ¡ jksFt	‚d S )NT)r   ZfooÚbar)
r   r   Zsuptitler   ZcanvasZdrawZget_window_extentZy0Úy1r   )r   r   ÚstÚtr   r   r   Útest_suptitle3  s
    


r‡   Zpdfc                s@   t jjj‰ ‡ fdd„}|  t jjd|¡ t ¡ \}}| ¡  d S )Nc                s(   t | tjjjƒst‚ˆ | f|ž|Ž d S )N)rq   r9   ÚbackendsZbackend_pdfZRendererPdfr   )ÚselfÚargsÚkwargs)Úunpatched_initr   r   Ú__init__?  s    z'test_non_agg_renderer.<locals>.__init__r�   )r9   Zbackend_basesZRendererBaser�   Úsetattrr   r   r   )ZmonkeypatchZrecwarnr�   r   r   r   )rŒ   r   Útest_non_agg_renderer;  s
    
r�   )r   )r,   rZ   r[   )*r4   Znumpyr/   Znumpy.testingr   r|   Z
matplotlibr9   Zmatplotlib.testing.decoratorsr   Zmatplotlib.pyplotZpyplotr   Zmatplotlib.offsetboxr   r   Zmatplotlib.patchesr   r   r   r    r%   r)   r0   r@   rD   rF   rI   rY   rf   rr   rs   ÚmarkZparametrizerw   rx   ry   r~   r‚   r‡   Úbackendr�   r   r   r   r   Ú<module>   s:   
	*		!
(	