3
$ßL]ˆ(  ã               @   sr  d dl Z d dlZd dlmZ d dlmZ d dljZ	d dl
mZmZ d dlmZ dAdd„Zed	gd
�dd„ ƒZedgd
�dd„ ƒZedgd
�dd„ ƒZedgdBd�dd„ ƒZedgd
�dd„ ƒZedgd
�dd„ ƒZedgd
�d d!„ ƒZed"gd
�d#d$„ ƒZed%gd
�d&d'„ ƒZd(d)„ ZdCd-d.„Zed/d0gd
�d1d2„ ƒZd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Zd;d<„ Z d=d>„ Z!d?d@„ Z"dS )Dé    N)Úassert_array_equal)Úimage_comparison)ÚAnchoredOffsetboxÚDrawingArea)Ú	Rectangleé   c             C   sH   | j 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   úI/tmp/pip-install-edjban26/matplotlib/matplotlib/tests/test_tightlayout.pyÚexample_plot   s
    r   Ztight_layout1)Úbaseline_imagesc              C   s$   t jƒ \} }t|dd� t jƒ  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 jƒ  dS )z'Test tight_layout for multiple subplotsr	   )ZnrowsZncolsN)r   r   r   r   )r   Úax1Úax2Úax3Úax4r   r   r   Útest_tight_layout2   s    r!   Ztight_layout3c              C   sJ   t jƒ } t jdƒ}t jdƒ}t jdƒ}t|ƒ t|ƒ t|ƒ t jƒ  dS )z'Test tight_layout for multiple subplotséÝ   éß   éz   N)r   ÚfigureÚsubplotr   r   )r   r   r   r   r   r   r   Útest_tight_layout3'   s    


r'   Ztight_layout4ú2.5.5ú2.6.1)r   Zfreetype_versionc              C   sr   t jƒ } t j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 jƒ  dS )z"Test tight_layout for subplot2gridr
   r   r   r	   )Úcolspan)r*   Úrowspan)r+   N)r
   r
   )r   r   )r
   r
   )r   r   )r
   r
   )r   r   )r
   r
   )r   r	   )r   r%   Úsubplot2gridr   r   )r   r   r   r   r    r   r   r   Útest_tight_layout48   s    r-   Ztight_layout5c              C   s<   t jƒ } t jdƒ}tjdƒjdƒ}|j|dd� t jƒ  dS )zTest tight_layout for imageéo   éd   é
   Únone)ÚinterpolationN)r0   r0   )r   r%   r&   ÚnpZarangeZreshapeZimshowr   )r   r   Zarrr   r   r   Útest_tight_layout5L   s
    
r4   Ztight_layout6c        
      C   s^  t jƒ ��J t jdtƒ tjƒ } ddlj}|jddƒ}| j	|d ƒ}| j	|d ƒ}t
|ƒ t
|ƒ |j| ddddgd� |jddƒ}x2|D ]*}| j	|ƒ}t
|ƒ |jd	ƒ |j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   Nr	   r   g      à?)Úrectr
   Ú zx-labelr   )r   gÍÌÌÌÌÌÜ?)r6   Zh_pad)ÚwarningsÚcatch_warningsÚsimplefilterÚUserWarningr   r%   Zmatplotlib.gridspecÚgridspecZGridSpecÚadd_subplotr   r   r   r   ÚminÚtopÚmaxÚbottom)
r   r<   Zgs1r   r   Zgs2Ússr   r?   rA   r   r   r   Útest_tight_layout6Y   s2    



rC   Ztight_layout7c              C   sr   d} t jƒ \}}|jddgƒ |jdd� |jd| d� |jd| d� |jd	d
| d� |jdd| d� t jƒ  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_layout7…   s    rG   Ztight_layout8c              C   s0   t jƒ } | jddiƒ | jdƒ}t|dd� dS )z"Test automatic use of tight_layoutÚpadgš™™™™™¹?r.   r   )r   N)r   r%   Zset_tight_layoutr=   r   )r   r   r   r   r   Útest_tight_layout8“   s    
rI   Ztight_layout9c              C   s.   t jddƒ\} }|d d jdƒ t jƒ  d S )Nr	   r   F)r   r   Úset_visibler   )ÚfZaxarrr   r   r   Útest_tight_layout9œ   s    rL   c              C   s�  t jƒ } | j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� | jdƒ}|jjdddd� |jjdddd� | jdƒ}|jjdddd� |jjdddd� | jdƒ}|jjdddd� |jjdddd� t jƒ  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j|jƒ jƒ dƒ|| ƒ �q`W dS )z"Test automatic use of tight_layoutr"   Úouté   r
   )ÚtickdirÚlengthÚwidthé    TÚminor)rO   rP   rQ   Ztick1OnÚwhichr   )rS   éÞ   Úinr#   Zinoutéà   g²�ï§ÆK·?g�•C‹lã?gƒÀÊ¡E¶Û?gB`åÐ"Ûí?gºI+‡â?g/Ý$�í?gìQ¸…ëÁ?gmçû©ñÒÝ?N)r   r%   r=   ZxaxisZset_tick_paramsZyaxisZ	set_ticksr   Ú	enumerateZaxesr   r3   ÚroundÚget_positionZ
get_points)r   r   ZansÚnnr   r   r   Útest_outward_ticks¥   s6    



r\   r0   çš™™™™™¹?Ú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�}	|j|	ƒ td|dd|| jdd	�}
| j|
ƒ q\W |
S )z&
    Surround ax with OffsetBoxes
    r   g      à?r   ÚNoneF)rQ   ÚheightZ	facecolorZ	edgecolorZ	linewidthZantialiasedÚcenterg        )rE   ÚchildrH   ZframeonZbbox_to_anchorZbbox_transformZ	borderpad)r   r   )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.    


ri   Ztight_layout_offsetboxes1Ztight_layout_offsetboxes2c                 s–   d ‰‰ddddg‰ ddg ‰‰‡ ‡‡‡‡fdd	„} | ƒ }t jƒ  | ƒ }x@|ˆd d ˆ… D ]*}x$|jƒ D ]}t|tƒrj|jd
ƒ qjW q\W t jƒ  d S )Nr	   ZredZblueZgreenZyellowr   r   c                 sP   t jˆˆƒ\} }|j}x4t|ˆ ƒD ]&\}}|jˆˆ|d� t|d|d� q"W |S )N)re   é   )r   r   ZflatÚzipr   ri   )Ú_Úaxsr   re   )ÚcolorsÚcolsÚrowsÚxÚyr   r   Ú	_subplots÷   s    z0test_tight_layout_offsetboxes.<locals>._subplotsF)r   r   Zget_childrenÚ
isinstancer   rJ   )rs   rm   r   rb   r   )rn   ro   rp   rq   rr   r   Útest_tight_layout_offsetboxesä   s    	
ru   c              C   s   t jƒ } | jƒ  dS )zOTests 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    rv   c           	   C   sR   t jd
d�\} }|jdd ƒ tjdd��}| jƒ  t|ƒdksDt‚W d	Q R X d	S )z-Test that warning emitted when xlabel too bigr
   r	   )ÚfigsizeÚar/   T)Úrecordr   N)r
   r	   )r   r   r   r8   r9   r   ÚlenÚAssertionError)r   r   Úwr   r   r   Ú"test_verybig_decorators_horizontal  s
    r}   c           	   C   sR   t jd
d�\} }|jdd ƒ tjdd��}| jƒ  t|ƒdksDt‚W d	Q R X d	S )z-Test that warning emitted when xlabel too bigr
   r	   )rw   rx   r/   T)ry   r   N)r
   r	   )r   r   r   r8   r9   r   rz   r{   )r   r   r|   r   r   r   Ú test_verybig_decorators_vertical  s
    r~   c           	   C   sl   t jdddd�\} }|d jdd ƒ |d jdd ƒ tjd	d
��}| jƒ  t|ƒdks^t‚W dQ R X dS )z-Test that warning emitted when xlabel too bigr   r	   r
   )rw   r   rx   é   ÚbT)ry   N)r
   r	   )r   r   r   r8   r9   r   rz   r{   )r   rm   r|   r   r   r   Útest_big_decorators_horizontal(  s    r�   c           	   C   sd   t jdddd�\} }|d jdƒ |d jdƒ tjd	d
��}| jƒ  t|ƒdksVt‚W dQ R X dS )z-Test that warning emitted when xlabel too bigr	   r   r
   )rw   r   rx   rj   r€   T)ry   N)r
   r	   ZaaaaaaaaaaaaaaaaaaaaZbbbbbbbbbbbbbbbbbbbb)r   r   r   r8   r9   r   rz   r{   )r   rm   r|   r   r   r   Útest_big_decorators_vertical2  s    r‚   c           	   C   sR   t jd	d
ƒ} t jddddd�}tjdd��}t jƒ  t|ƒdksDt‚W d Q R X d S )Né   é   r   r
   )r*   r+   T)ry   r   )rƒ   r„   )r   r   )r„   r„   )r   r
   )r   r,   r8   r9   r   rz   r{   )r   Zax5r|   r   r   r   Útest_badsubplotgrid<  s
    r…   c              C   s¤   t jdd�\} }|jddgƒ |jddgƒ |jdddd
� |jƒ }tjdd��6}t jƒ  |jƒ }|j	|j	ksrt
‚t|ƒdks‚t
‚W d Q R X t jddddgd� d S )NT)r   r   r   zBIG LONG STRINGç      ô?r	   ç      %@ç      ü?)ZxyZxytext)ry   gš™™™™™é?)r6   )r†   r	   )r‡   rˆ   )r   r   Zset_xlimZset_ylimZannotaterZ   r8   r9   r   rQ   r{   rz   )r   r   Úp1r|   Úp2r   r   r   Útest_collapsedG  s    r‹   )r   )r(   r)   )r0   r]   r^   )#r8   Znumpyr3   Znumpy.testingr   Zmatplotlib.testing.decoratorsr   Zmatplotlib.pyplotZpyplotr   Zmatplotlib.offsetboxr   r   Zmatplotlib.patchesr   r   r   r!   r'   r-   r4   rC   rG   rI   rL   r\   ri   ru   rv   r}   r~   r�   r‚   r…   r‹   r   r   r   r   Ú<module>   s8   

,		!
(			

