a
    s=icjT                  
   @   s  d dl Z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 d}ddZd~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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dRd[d\d] Z-ed^gdRd[d_d` Z.dadb Z/edcgdQdRdddeidfdgdh Z0edigdQdRdde1djd gdkdlggidfdmdn Z2dodp Z3dqdr Z4dsdt Z5dudv Z6dwdx Z7dydz Z8d{d| Z9dS )    N)image_comparison)gridspecticker   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   x/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/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 subplotconstrainedlayout   r   N)pltfigureadd_subplotr   figr   r   r   r   test_constrained_layout1$   s    r2   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   r)   r*   r,   r   N)r-   subplotsflatr   r1   axsr   r   r   r   test_constrained_layout2,   s    
r7   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   r)   r*   r,   r   r   g{Gz?{Gz?)r   padN)r-   r3   	enumerater4   r(   colorbar)r1   r6   nnr   r'   r9   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   r)   r*   r,   r   {Gz?r   r   r9   shrinkNr-   r3   r4   r(   r;   r1   r6   r   r'   r   r   r   test_constrained_layout4B   s    
rC   zconstrained_layout5.pnggMb`?)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   r)   r*   r,   r   Fr>   r   bottom)r   Zuse_gridspecr9   r@   locationNrA   rB   r   r   r   test_constrained_layout5L   s    
rF   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.snapr)   r*   r   r   r.   r   r   r   zx-label
MultiLiner>   gGz?rD   r   r	   )r   r9   r@   rE   ZticksN)r-   rcParamsr.   add_gridspecsubgridspecr/   r   r   r(   r;   r   ZMaxNLocator)r1   gsgslgsrZaxslr   Zaxsrr'   r   r   r   test_constrained_layout6[   s(    






rO   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sJ d S )NTZconstrained_layoutr   r   r   r   )
r-   r.   rJ   rK   ranger/   draw_without_renderingget_positiony0y1)r1   ZGSZGSAZGSBZaxaZaxbir   r   r   test_identical_subgridspecv   s    rW   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matchr)   r*   r   r   r   N)
pytestwarnsUserWarningr-   r.   r   GridSpecGridSpecFromSubplotSpecr/   rR   )r1   rL   rM   rN   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   r)   figsizer+   r   r   rH   r   r   r   r      	   r    r   Nr>   r   r?   )
r-   r.   r   r]   r/   r(   r   r   r   r;   )r1   rL   r6   jZilistrV   r   r'   r   r   r   test_constrained_layout8   s(    



rh   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   r)   Fr+   sharexshareyr,   r   rf   r   r>   r   r?   zTest Suptitle   N)	r-   r3   r4   r(   r   r   
set_aspectr;   suptitlerB   r   r   r   test_constrained_layout9   s    




ro   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   r)   r*   r   zThis is a label)labelzcenter left)g?      ?)locZbbox_to_anchorN)r-   r3   r4   r   r    Zarangelegendr5   r   r   r   test_constrained_layout10   s    
rt   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 gridspecsr)   )   r   r+   rb   r   r   rH   r   re   r   r        Q@r   r@   aspectN	r-   r.   r   r]   r^   r/   r   r(   r;   r1   gs0rM   Zgsl0r   r6   rL   r'   r   r   r   test_constrained_layout11   s    

r}   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_ratiosr)   )r`   r   rv   r   r      )r.   Zwidth_ratiosr   )height_ratiosre   r   r   rw   rx   Nrz   r{   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.r)   )r~      rv   r~   r   rH   Nr   r      r   r   T)r   rd   r
   )r-   r.   r   r]   r/   r   r   )r1   r|   ax1ax2r   r   r   r   test_constrained_layout12   s    r   zconstrained_layout13.pngr8   c                  C   s   t jdddd\} }|jD ]$}t|dd}| j||dddd	 qtt" |  j	d
dd W d   n1 sr0    Y  |  j	ddd dS )Test that padding works.r   r)   r*   r   r   r         4@r8   r   r@   ry   r9   r   )ZwpadZhpadNgUUUUUU?w_padh_pad)
r-   r3   r4   r(   r;   rZ   Zraises	TypeErrorget_layout_enginesetrB   r   r   r   test_constrained_layout13  s    
0r   zconstrained_layout14.pngc                  C   sZ   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   r)   r*   r   r   r   r   r8   r   gUUUUUU?皙?r   r   ZhspaceZwspaceN)r-   r3   r4   r(   r;   r   r   rB   r   r   r   test_constrained_layout14  s    
r   zconstrained_layout15.pngc                  C   s6   dt j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)mplrI   r-   r3   r4   r   r5   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.r)   r*   r   r   )r   r   皙?r   N)r-   r3   r   add_axesr1   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 gridspecsr)   r*   r   rH   r   r   r   r   Nr   r   )r-   r.   r   r]   r/   r   )r1   rL   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 twinxr)   r*   r,   r   N)r-   r3   Ztwinxr   rR   allrS   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 twinyr)   r*   r,   r   rf   N)	r-   r3   Ztwinyr   r   rR   r   rS   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 axesr   rd   N)r   r   r   r   r   )r    Zlinspacehypotr-   r.   r   r#   r;   )ZgxZimgr1   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 layoutr)   r*   Z	Suptitle0Z	Suptitle1N)
r-   r3   rn   rR   r    copyrS   r   testingassert_allcloser1   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 positionedr)   r*   ZSuptitlerq   r$   N)
r-   r3   rR   r    r   rS   r   rn   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   r)   TZ123)r+   clearnumr   r   z
Suptitle{}N)rQ   r-   r.   rJ   rK   rn   format)rV   r1   rL   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...
    FrG   rd   r   r)   r*   rf   Nr   r   )r   r@   r   r   rq   rD   )r   r@   rE   r   g?)r   r@   rE   r9   r   topr   leftright)r-   rI   r3   r4   r(   r   r   r;   rB   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   r)   r*   rc   Fr   )g|R?g\	b?g&:?g9?q?h㈵>)rtol)
r-   r3   Zset_visiblerR   r    r   rS   r   r   r   )r1   r6   r   r   r   r   test_hidden_axes  s    
r   c               	   C   sv  dD ]j} 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   rD   r   r)   r*   in)	directionr   g{Gz?)r   rE   r@   r9   r   gqq?g?r   )r   r   r   r   )r-   r3   r:   r4   tick_paramsr(   r;   r   ZxaxisZ	set_ticksyaxisr   r   r   r   rR   r    r   r   rS   x0rT   )rE   r1   r6   Zcbsr<   r   pccbr   r   r   test_colorbar_align  sB    



r   ztest_colorbars_no_overlapV.png)r   c                  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   rd   r)   ra   r   r   Trj   rk   bothr   Zaxisr   r   rd   verticalr   Zorientationfoo)r-   r.   r3   r   set_major_formatterr   NullFormatterr   imshowr;   rn   r1   r6   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)rd   r   r)   ra   r   r   r   Tr   r   r   r   r   rd   
horizontalr   )r-   r.   rn   r3   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   r)   r*   r   r   r   333333?r   r   rq      r   g)\(?)r-   r3   Zset_positionrR   rS   r    r   r   r#   randomZrandr;   )r1   r6   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 Nr)   r*   r   r-   r3   rm   r0   r   r   r   test_bboxtight  s    r   ztest_bbox.pngrq   g      @r   c                  C   s   t jdd\} }|d d S r   r   r0   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sJ 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   r)   )g@r   r   )r   r   gffffff?)r+   rb   Zgridspec_kwr   Labelg      g      ?)r6   r   r   )r   atolN)r-   r3   Zset_ylimr   Zalign_ylabelsrR   r   rp   Zget_window_extentr    r   r   r   )r1   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sJ |j	|j	d ksJ d S )	Nr)   r*   BooZBooyg      $@rq   )r%   r   )
r-   r3   rR   Zget_tightbboxZcanvasZget_rendererZ	supxlabelZ	supylabelrT   r   )r1   r   Zpos0posr   r   r   test_suplabels0  s$    

r   c                  C   s:   t  } | dd}| |dd dd f }|   d S )Nr   r   r   )r-   r.   rJ   r/   rR   )r1   rL   spr   r   r   test_gridspec_addressingG  s    r   c                  C   s   t jdd\} }|   tjtdd. t  \} }| d |   W d    n1 sZ0    Y  tjtdd4 t  \} }| ddd |   W d    n1 s0    Y  d S )NTrP   zwill be deprecatedrX   r8   r   )r-   r3   rR   rZ   r[   PendingDeprecationWarningZset_constrained_layoutr0   r   r   r   test_discouraged_apiN  s    
&r   c                  C   s    t jddid\} }|   d S )Nr   r8   rP   )r-   r3   rR   r0   r   r   r   test_kwargs_  s    r   c                  C   s   t jdd\} }|  jg dd |   | }|jdk sBJ |jdk sPJ t jdd\} }|  jg dd |   | }|jdk sJ |jdk sJ |jdksJ |j	dksJ d S )Nr)   r*   )r   r   rq   rq   )rectrq   r   r   )
r-   r3   r   r   rR   rS   x1rU   r   rT   )r1   r   Zpposr   r   r   	test_rectd  s    r   c                  C   sJ  t jdddddd\} }|jD ]}|tjdd}q| j||d |   |d 	 }tj
j|jd	d
d |d 	 }tj
j|jdd
d t jddddddd\} }|jD ]}|tjdd}q| j||d |   |d 	 }tj
j|jdd
d tj
j|jdd
d |d 	 }tj
j|jdd
d tj
j|jdd
d d S )Nr   r   
compressedTri   r   r   r   gX ?gMbP?)r   rc   gz?)r   rd   )r+   rj   rk   rb   gGr鷯?gQ?)r   r   gk+ݓ?goT?)r-   r3   r4   r   r    r   Zrandnr;   rR   rS   r   r   r   r   rU   rT   )r1   r6   r   r   r   r   r   r   test_compressed1v  s0    





r   )r   F)r   ):numpyr    rZ   Z
matplotlibr   Zmatplotlib.testing.decoratorsr   Zmatplotlib.pyplotZpyplotr-   Zmatplotlib.transformsZ
transformsZmtransformsr   r   r   r(   r2   r7   r=   rC   rF   rO   rW   r_   rh   ro   rt   r}   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   r   r   r   r   <module>   s   





	














 



"