a
    #©b«L  ã                
   @   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 d dlmZmZ dtdd„Zdud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�dd„ ƒZ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/d0„ ƒZed1gƒd2d3„ ƒZed4gd5d�d6d7„ ƒZ ed8gƒd9d:„ ƒZ!ed;gƒd<d=„ ƒZ"ed>gƒd?d@„ ƒZ#edAgƒdBdC„ ƒZ$dDdE„ Z%dFdG„ Z&dHdI„ Z'dJdK„ Z(dLdM„ Z)dNdO„ Z*edPgdQdRdS�dTdU„ ƒZ+dVdW„ Z,dXdY„ Z-edZgddRdS�d[d\„ ƒZ.ed]gddRdS�d^d_„ ƒZ/d`da„ Z0edbgdQdRdcddide�dfdg„ ƒZ1edhgdQdRdce 2did gdjdkgg¡ide�dldm„ ƒZ3dndo„ Z4dpdq„ Z5drds„ Z6dS )vé    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|  g ¡ |  g ¡ d S )	Né   é   é   ©Znbinsúx-label©Úfontsizeúy-labelÚTitle)ÚplotZlocator_paramsÚ
set_xlabelÚ
set_ylabelÚ	set_titleÚset_xticklabelsÚset_yticklabels)Úaxr   Únodec© r   úp/home/yuhw/wc/wire-cell-python-pr-11/pr11/lib/python3.9/site-packages/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)ç333333ã?r   éýÿÿÿr   r   ç       @é   r   éÿÿÿÿZRdBu_rg      ð¿ç      ð?T)ZcmapZvminZvmaxZ
rasterizedr
   r   r   r   )Ú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�} |  ¡ }t|dd� dS )z,Test constrained_layout for a single subplotT©Úconstrained_layouté   r   N)ÚpltÚfigureÚadd_subplotr   ©Úfigr   r   r   r   Útest_constrained_layout1$   s    r1   zconstrained_layout2.pngc                  C   s0   t jdddd�\} }|jD ]}t|dd� qdS )z(Test constrained_layout for 2x2 subplotsr   Tr)   r+   r   N)r,   ÚsubplotsÚflatr   ©r0   Úaxsr   r   r   r   Útest_constrained_layout2,   s    
r6   zconstrained_layout3.pngc                  C   sZ   t jdddd�\} }t|jƒD ]6\}}t|dd�}|dkr@d}nd}| j|||d	� qd
S )z3Test constrained_layout for colorbars with subplotsr   Tr)   r+   r   r   g{®Gáz´?ç{®Gáz”?)r   ÚpadN)r,   r2   Ú	enumerater3   r(   Úcolorbar)r0   r5   Únnr   r'   r8   r   r   r   Útest_constrained_layout34   s    r<   zconstrained_layout4.pngc                  C   sB   t jdddd�\} }|jD ]}t|dd�}q| j||ddd� d	S )
z;Test constrained_layout for a single colorbar with subplotsr   Tr)   r+   r   ç{®Gáz„?r   ©r   r8   ÚshrinkN©r,   r2   r3   r(   r:   ©r0   r5   r   r'   r   r   r   Útest_constrained_layout4B   s    
rB   zconstrained_layout5.pnggü©ñÒMb`?)Ztolc                  C   sF   t jdddd�\} }|jD ]}t|dd�}q| j||dddd	d
� dS )zZ
    Test constrained_layout for a single colorbar with subplots,
    colorbar bottom
    r   Tr)   r+   r   Fr=   r   Úbottom)r   Zuse_gridspecr8   r?   ÚlocationNr@   rA   r   r   r   Útest_constrained_layout5L   s    
þrE   zconstrained_layout6.pngc               	   C   sÎ   dt jd< t jdd�} | jdd| d�}|d  dd¡}|d  dd¡}g }|D ]$}|  |¡}||g7 }t|d	d
� qN| d¡ g }|D ]$}|  |¡}||g7 }t|d	d
�}q†| j	||dddt
jdd�d� dS )z,Test constrained_layout for nested gridspecsFúpcolormesh.snapTr)   r   r   ©r-   r   r   r   zx-label
MultiLiner=   g®Gáz®ï?rC   r   r	   )r   r8   r?   rD   ZticksN)r,   r   r-   Úadd_gridspecÚsubgridspecr.   r   r   r(   r:   r   ZMaxNLocator)r0   ÚgsÚgslÚgsrZaxslr   Zaxsrr'   r   r   r   Útest_constrained_layout6[   s(    






þrM   c                  C   s¢   t jdd�} |  dd¡}|d  dd¡}|d  dd¡}g }g }tdƒD ],}||  || ¡g7 }||  || ¡g7 }qH|  ¡  |d  ¡ j|d  ¡ j	ksžJ ‚d S )NTr)   r   r   r   r   )
r,   r-   rH   rI   Úranger.   Údraw_without_renderingÚget_positionÚy0Úy1)r0   ZGSZGSAZGSBZaxaZaxbÚir   r   r   Útest_identical_subgridspecv   s    rT   c                  C   sŠ   t jtdd��h tjdd�} t dd¡}t dd|d ¡}t dd|d ¡}|D ]}|  |¡ qP|  	¡  W d  ƒ n1 s|0    Y  dS )	z2Test for proper warning if fig not set in GridSpeczhThere are no gridspecs with layoutgrids. Possibly did not call parent GridSpec with the "figure" keyword©ÚmatchTr)   r   r   r   N)
ÚpytestZwarnsÚUserWarningr,   r-   ÚgridspecÚGridSpecÚGridSpecFromSubplotSpecr.   rO   )r0   rJ   rK   rL   r   r   r   Útest_constrained_layout7Š   s    ÿr\   zconstrained_layout8.pngc                  C   sæ   t jddd�} tjdd| d�}g }dD ]|}|dkr:d	g}ndd
g}|D ]Z}|  |||f ¡}||g7 }t|dd�}|dkr„| d¡ |d	k r–| d¡ | d¡ qFq&|  |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   rG   ©r   r   r   r   é   é	   r   Ú r   Nr=   r   r>   )
r,   r-   rY   rZ   r.   r(   r   r   r   r:   )r0   rJ   r5   ÚjZilistrS   r   r'   r   r   r   Útest_constrained_layout8š   s(    



re   zconstrained_layout9.pngc                  C   sr   t jdddddd�\} }|jD ]$}t|dd�}| d¡ | d¡ q| d¡ | j||d	d
d� | jddd� dS )z4Test for handling suptitle and for sharex and shareyr   TF)r*   ÚsharexÚshareyr+   r   rc   r   r=   r   r>   zTest Suptitleé   N)	r,   r2   r3   r(   r   r   Ú
set_aspectr:   ÚsuptitlerA   r   r   r   Útest_constrained_layout9¶   s    
ÿ



rk   zconstrained_layout10.pngc                  C   sF   t jdddd�\} }|jD ]}|jt d¡dd� q|jddd	� d
S )z%Test for handling legend outside axisr   Tr)   r   zThis is a label)Úlabelzcenter left)gš™™™™™é?ç      à?)ÚlocZbbox_to_anchorN)r,   r2   r3   r   r    ZarangeZlegendr4   r   r   r   Útest_constrained_layout10Å   s    
ro   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 }|D ]$}|  |¡}||g7 }t|dd	�}qd| j||d
dd� |  |d ¡}t|dd	� dS )z"Test for multiple nested gridspecsT)é   r   ©r*   r_   r   r   rG   r   rb   r   r   ç     €Q@©r   r?   ÚaspectN©	r,   r-   rY   rZ   r[   r.   r   r(   r:   ©r0   Úgs0rK   Zgsl0r   r5   rJ   r'   r   r   r   Útest_constrained_layout11Î   s    

rx   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 }|D ]$}|  |¡}||g7 }t|d
d�}qr| j||ddd� |  |d ¡}t|d
d� dS )z4Test for multiple nested gridspecs with width_ratiosT)r]   r   rq   r   r   é   )r-   Zwidth_ratiosr   )Úheight_ratiosrb   r   r   rr   rs   Nru   rv   r   r   r   Útest_constrained_layout11ratâ   s    

r{   zconstrained_layout12.pngc                  C   sÖ   t jd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)ry   é   rq   ry   r   rG   Nr   r   é   r   r   )r   ra   r
   )r,   r-   rY   rZ   r.   r   r   )r0   rw   Úax1Úax2r   r   r   r   Útest_constrained_layout12ö   s    r€   zconstrained_layout13.pngr7   c                  C   sŽ   t jdddd�\} }|jD ]$}t|dd�}| j||dddd	� qtjtd
d�� | jddd� W d  ƒ n1 sr0    Y  | jddd� dS )úTest that padding works.r   Tr)   r   r   r   ç      4@r7   ©r   r?   rt   r8   zunexpected keyword argumentrU   r   )ZwpadZhpadNgUUUUUUÕ?)Úw_padÚh_pad)	r,   r2   r3   r(   r:   rW   ZraisesÚ	TypeErrorÚset_constrained_layout_padsrA   r   r   r   Útest_constrained_layout13  s    
,rˆ   zconstrained_layout14.pngc                  C   sV   t jdddd�\} }|jD ]$}t|dd�}| j||dddd	� q| jd
d
ddd� dS )r�   r   Tr)   r   r   r   r‚   r7   rƒ   gUUUUUU¥?çš™™™™™É?©r„   r…   ZhspaceZwspaceN)r,   r2   r3   r(   r:   r‡   rA   r   r   r   Útest_constrained_layout14  s    
þr‹   zconstrained_layout15.pngc                  C   s4   dt d< t dd¡\} }|jD ]}t|dd� qdS )zTest that rcparams work.Tzfigure.constrained_layout.user   r   r   N)r   r,   r2   r3   r   r4   r   r   r   Útest_constrained_layout15$  s    
rŒ   zconstrained_layout16.pngc                  C   s.   t jdd�\} }t|dd� |  g d¢¡}dS )zTest ax.set_position.Tr)   r   r   )r‰   r‰   çš™™™™™Ù?r�   N)r,   r2   r   Úadd_axes©r0   r   r   r   r   r   Útest_constrained_layout16-  s    r�   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 gridspecsTr)   r   rG   ©r   r   r   r   Nr   r   )r,   r-   rY   rZ   r.   r   )r0   rJ   r~   r   Úax3Zax4r   r   r   Útest_constrained_layout175  s    r“   c                  C   sT   t jdd�\} }| ¡ }t|ƒ t|dd� |  ¡  t| ¡ j| ¡ jkƒsPJ ‚dS )z
Test twinxTr)   r+   r   N)r,   r2   Ztwinxr   rO   ÚallrP   Úextentsr�   r   r   r   Útest_constrained_layout18F  s    r–   c                  C   sh   t jdd�\} }| ¡ }t|ƒ t|dd� | d¡ | d¡ |  ¡  t| ¡ j| ¡ jkƒsdJ ‚dS )z
Test twinyTr)   r+   r   rc   N)	r,   r2   Ztwinyr   r   rO   r”   rP   r•   r�   r   r   r   Útest_constrained_layout19P  s    

r—   c                  C   sh   t  ddd¡} t  | | dd…df ¡}t ¡ }| g d¢¡}| | | |dd…dd…f ¡}| |¡ dS )z)Smoke test cl does not mess up added axeséûÿÿÿr   ra   N)r   r   r   r   r   )r    ZlinspaceÚhypotr,   r-   rŽ   r#   r:   )ZgxÚimgr0   r   Zmeshr   r   r   Útest_constrained_layout20\  s    r›   c                  C   sf   t jdd�\} }|  d¡ |  ¡  t | ¡ j¡}|  d¡ |  ¡  t | ¡ j¡}tj 	||¡ dS )z>#11035: repeated calls to suptitle should not alter the layoutTr)   Z	Suptitle0Z	Suptitle1N)
r,   r2   rj   rO   r    ÚcopyrP   r•   ÚtestingÚassert_allclose©r0   r   Zextents0Úextents1r   r   r   Útest_constrained_layout21g  s    

r¡   c                  C   s`   t jdd�\} }|  ¡  t | ¡ j¡}| jddd� |  ¡  t | ¡ j¡}tj 	||¡ dS )zC#11035: suptitle should not be include in CL if manually positionedTr)   ZSuptitlerm   ©r$   N)
r,   r2   rO   r    rœ   rP   r•   rj   r�   rž   rŸ   r   r   r   Útest_constrained_layout22v  s    r£   c                  C   sN   t dƒD ]@} tjdddd�}| dd¡}|d  dd¡}| d | ¡¡ qdS )	zu
    Comment in #11035: suptitle used to cause an exception when
    reusing a figure w/ CL with ``clear=True``.
    r   TZ123)r*   ÚclearÚnumr   r   z
Suptitle{}N)rN   r,   r-   rH   rI   rj   Úformat)rS   r0   rJ   Úsubr   r   r   Útest_constrained_layout23„  s
    r¨   ztest_colorbar_location.pngTZmpl20)Úremove_textÚstylec                  C   sö   dt jd< t jdddd�\} }|jD ] }t|ƒ}| d¡ | d¡ q$| j||dd…d	f d
d� | j||ddd…f ddd� | j||ddd…f d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...
    FrF   ra   r   Tr)   rc   Nr   r�   )r   r?   r   r   rm   rC   )r   r?   rD   r   gš™™™™™©?)r   r?   rD   r8   éþÿÿÿr   Útopr‘   ÚleftÚright)r,   r   r2   r3   r(   r   r   r:   rA   r   r   r   Útest_colorbar_location‘  s    


 r¯   c                  C   sX   t jdddd�\} }|d  d¡ |  ¡  t |d  ¡ j¡}tjj	|g d¢dd	� d S )
Nr   Tr)   r`   Fr‘   )g›çˆ|—R§?g\å	„�bá?g&�Ñ:ªšÞ?g³Ñ9?Åqï?çñhãˆµøä>)Úrtol)
r,   r2   Zset_visiblerO   r    rœ   rP   r•   r�   rž   )r0   r5   r    r   r   r   Útest_hidden_axes¨  s    
ÿr²   c               	   C   sr  dD �]f} t jdddd�\}}g }t|jƒD ]€\}}|jdd� t|ƒ}|j||| ddd	�}||g7 }|jjdd� |d
kr,|jj 	g ¡ |jj
 	g ¡ | g ¡ | g ¡ q,|jddddd� | ¡  | dv �r tj |d j ¡ j|d j ¡ j¡ tj |d
 j ¡ j|d j ¡ j¡ qtj |d j ¡ j|d
 j ¡ j¡ tj |d j ¡ j|d j ¡ j¡ qd S )N)r®   r­   r¬   rC   r   Tr)   Úin)Ú	directionr   g{®Gáz¤?)r   rD   r?   r8   r   gÇqÇq¬?gš™™™™™¹?rŠ   )r­   r®   r   r   )r,   r2   r9   r3   Útick_paramsr(   r:   r   ZxaxisZ	set_ticksÚyaxisr   r   r‡   rO   r    r�   rž   rP   Úx0rQ   )rD   r0   r5   Zcbsr;   r   ÚpcÚcbr   r   r   Útest_colorbar_alignµ  sB    
ÿ


ÿ
ÿÿÿÿrº   ztest_colorbars_no_overlapV.pngc                  C   s|   t jddd�} | jddddd�}|D ]H}|j t ¡ ¡ |jddd	� | ddgd
dgg¡}| j	||dd� q$|  
d¡ d S )N)r   ra   Tr^   r   r   ©rf   rg   Úbothr³   ©Zaxisr´   r   ra   Zvertical©r   ZorientationÚfoo)r,   r-   r2   r¶   Úset_major_formatterr   ÚNullFormatterrµ   Úimshowr:   rj   ©r0   r5   r   Zimr   r   r   Útest_colorbars_no_overlapVÕ  s    rÄ   ztest_colorbars_no_overlapH.pngc                  C   s|   t jddd�} |  d¡ | jddddd�}|D ]H}|j t ¡ ¡ |jdd	d
� | 	ddgddgg¡}| j
||dd� q.d S )N)ra   r   Tr^   r¿   r   r   r»   r¼   r³   r½   r   ra   Z
horizontalr¾   )r,   r-   rj   r2   r¶   rÀ   r   rÁ   rµ   rÂ   r:   rÃ   r   r   r   Útest_colorbars_no_overlapHâ  s    
rÅ   c                  C   sÖ   t jdddd�\} }|d  g d¢¡ |  ¡  |d  ¡ }tj |ddgddgg¡ t jdddd�\} }|d  g d¢¡ |d  tj	 
d	d	¡¡}| j||d d
� |  ¡  |d  ¡ }tj |ddgddgg¡ d S )Nr   r   Tr)   r   )r‰   r‰   ç333333Ó?rÆ   r‰   rm   é   )r   g)\�Âõ(Ü?)r,   r2   Zset_positionrO   rP   r    r�   rž   r#   ÚrandomZrandr:   )r0   r5   Úppr¸   r   r   r   Útest_manually_set_positionï  s    rÊ   ztest_bboxtight.pngZbbox_inchesZtight)r©   rª   Zsavefig_kwargc                  C   s   t jdd�\} }| d¡ d S ©NTr)   r   ©r,   r2   ri   r/   r   r   r   Útest_bboxtightÿ  s    rÍ   ztest_bbox.pngrm   g      @r   c                  C   s   t jdd�\} }| d¡ d S rË   rÌ   r/   r   r   r   Ú	test_bbox  s    rÎ   c                  C   sà   t jddddddid�\} \}}}| dd¡ | d	¡ | d
d¡ | d	¡ | dd¡ | d	¡ | j|||fd� |  ¡  |jj ¡ |jj ¡ |jj ¡ g}t	j
j|d j|d jg|d jddd� |d jdksÜJ ‚dS )zî
    Tests for a bug in which constrained layout and align_ylabels on
    three unevenly sized subplots, one of whose y tick labels include
    negative numbers, drives the non-negative subplots' y labels off
    the edge of the plot
    r   r   T)gš™™™™™@r|   rz   )r   r   gffffffæ?)r*   r_   Zgridspec_kwr   ZLabelg      ø¿g      ø?)r5   r   r°   )r±   ZatolN)r,   r2   Zset_ylimr   Zalign_ylabelsrO   r¶   rl   Zget_window_extentr    r�   rž   r·   )r0   r’   r~   r   Zafter_alignr   r   r   Útest_align_labels  s(    
þ





þÿrÏ   c                  C   s  t jdd�\} }|  ¡  | | j ¡ ¡}|  d¡ |  d¡ |  ¡  | | j ¡ ¡}|j|jd kshJ ‚|j	|j	d ks|J ‚t jdd�\} }|  ¡  | | j ¡ ¡}| jddd� | jddd� |  ¡  | | j ¡ ¡}|j|jd ksìJ ‚|j	|j	d k�sJ ‚d S )	NTr)   ZBooZBooyg      $@rm   )r%   r¢   )
r,   r2   rO   Zget_tightbboxZcanvasZget_rendererZ	supxlabelZ	supylabelrQ   r·   )r0   r   Zpos0Úposr   r   r   Útest_suplabels2  s$    

rÑ   c                  C   s:   t  ¡ } |  dd¡}|  |dd …dd …f ¡}|  ¡  d S )Nr   r   r   )r,   r-   rH   r.   rO   )r0   rJ   Úspr   r   r   Útest_gridspec_addressingI  s    rÓ   )r   F)r   )7Únumpyr    rW   Zmatplotlib.testing.decoratorsr   Zmatplotlib.pyplotZpyplotr,   Zmatplotlib.gridspecrY   Zmatplotlib.transformsZ
transformsZmtransformsZ
matplotlibr   r   r   r(   r1   r6   r<   rB   rE   rM   rT   r\   re   rk   ro   rx   r{   r€   rˆ   r‹   rŒ   r�   r“   r–   r—   r›   r¡   r£   r¨   r¯   r²   rº   rÄ   rÅ   rÊ   rÍ   ZBboxrÎ   rÏ   rÑ   rÓ   r   r   r   r   Ú<module>   s    





	













ÿ
 ÿ
ÿ
þ
ÿþ
"