o
    gL                  
   @   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 dpddZdqd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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dNgdOdPdQdRdS Z*dTdU Z+dVdW Z,edXgddPdQdYdZ Z-ed[gddPdQd\d] Z.d^d_ Z/ed`gdOdPdadbidcddde Z0edfgdOdPdae1dgd gdhdiggidcdjdk Z2dldm Z3dndo Z4dS )r    N)image_comparison)tickerrcParams   Fc                 C   sd   |  ddg | jdd |s&| jd|d | jd|d | jd|d d S | d	 | d	 d S )
N         nbinsx-labelfontsizey-labelTitle )plotlocator_params
set_xlabel
set_ylabel	set_titleset_xticklabelsset_yticklabels)axr   nodec r   e/home/ubuntu/cloudmapper/venv/lib/python3.10/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   RdBu_rg            ?T)cmapvminvmax
rasterizedr   r   r   r   )npmgridsliceexp
pcolormeshr   r   r   )r   r   dxdyyxzpcmr   r   r   example_pcolor   s   
4 r3   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   r<   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   Tr4   r6   r   N)r7   subplotsflatr   r;   axsr   r   r   r   test_constrained_layout2,   s   
rA   zconstrained_layout3.pngc                  C   sd   dt jd< t jdddd\} }t|jD ]\}}t|dd}|dkr%d	}nd
}| j|||d qdS )z3Test constrained_layout for colorbars with subplotsFpcolormesh.snapr   Tr4   r6   r   r   g{Gz?{Gz?)r   padN)r7   r   r=   	enumerater>   r3   colorbar)r;   r@   nnr   r2   rD   r   r   r   test_constrained_layout34   s   
rH   zconstrained_layout4.pngc                  C   sL   dt jd< 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 subplotsFrB   r   Tr4   r6   r   {Gz?r   r   rD   shrinkNr7   r   r=   r>   r3   rF   r;   r@   r   r2   r   r   r   test_constrained_layout4D   s
   

rN   zconstrained_layout5.pnggMb`?)tolc                  C   sP   dt jd< 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
    FrB   r   Tr4   r6   r   rI   r   bottom)r   use_gridspecrD   rK   locationNrL   rM   r   r   r   test_constrained_layout5P   s   


rS   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
 q'|d g }|D ]}| |}||g7 }t|d	d
}qC| j	||dddt
jddd dS )z,Test constrained_layout for nested gridspecsFrB   Tr4   r   r   r8   r   r   r   zx-label
MultiLinerI   gGz?rP   r    r	   )r   rD   rK   rR   ticksN)r7   r   r8   add_gridspecsubgridspecr9   r   r   r3   rF   r   MaxNLocator)r;   gsgslgsraxslr   axsrr2   r   r   r   test_constrained_layout6a   s(   







r^   c                  C   s   t jtdd9 tjdd} tdd}tdd|d }tdd|d }|D ]}| | q(| 	| j
  W d   dS 1 sCw   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)matchTr4   r   r   r   N)pytestwarnsUserWarningr7   r8   gridspecGridSpecGridSpecFromSubplotSpecr9   drawcanvasget_renderer)r;   rY   rZ   r[   r   r   r   test_constrained_layout7|   s   "ri   zconstrained_layout8.pngc                  C   s   dt jd< t jddd} tjdd| d}g }d	D ]>}|d
kr"dg}nd
dg}|D ]-}| |||f }||g7 }t|dd}|d
krG|d |dk rP|d |	d q(q| |dddf }||g7 }t|dd}| j
||ddd dS )z/Test for gridspecs that are not completely fullFrB   )
   r    Tfigsizer5   r   r    rT   r   r   r   r      	   r   r   r   NrI   r   rJ   )r7   r   r8   rc   rd   r9   r3   r   r   r   rF   )r;   rY   r@   jilistir   r2   r   r   r   test_constrained_layout8   s,   



	
rs   zconstrained_layout9.pngc                  C   s|   dt jd< 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 shareyFrB   r   T)r5   sharexshareyr6   r   r   r   rI   r   rJ   zTest Suptitle   N)
r7   r   r=   r>   r3   r   r   
set_aspectrF   suptitlerM   r   r   r   test_constrained_layout9   s   





ry   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   Tr4   r   zThis is a label)labelzcenter left)g?      ?)locbbox_to_anchorN)r7   r=   r>   r   r(   arangelegendr?   r   r   r   test_constrained_layout10   s   
r   zconstrained_layout11.pngc                  C   s   dt jd< 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}q7| j	||ddd | |d	 }t|d
d dS )z"Test for multiple nested gridspecsFrB   T)   r   r5   rl   r   r   rT   r   ro   r   r        Q@r   rK   aspectN
r7   r   r8   rc   rd   re   r9   r   r3   rF   r;   gs0rZ   gsl0r   r@   rY   r2   r   r   r   test_constrained_layout11   s   


r   zconstrained_layout11rat.pngc                  C   s   dt jd< 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}q>| j	||ddd | |d
 }t|dd dS )z4Test for multiple nested gridspecs with width_ratiosFrB   T)rj   r   r   r   r      )r8   width_ratiosr   )height_ratiosro   r   r   r   r   Nr   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.T)r      r   r   r   rT   Nr   r      r   r   )r   rn   r   )r7   r8   rc   rd   r9   r   r   )r;   r   ax1ax2r   r   r   r   test_constrained_layout12   s   r   zconstrained_layout13.pngrC   c                  C   s\   dt jd< t jdddd\} }|jD ]}t|dd}| j||dd	d
d q| jddd dS )Test that padding works.FrB   r   Tr4   r   r   r         4@rC   r   rK   r   rD   gUUUUUU?)w_padh_padNr7   r   r=   r>   r3   rF   set_constrained_layout_padsrM   r   r   r   test_constrained_layout13  s   

r   zconstrained_layout14.pngc                  C   s`   dt jd< 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   FrB   r   Tr4   r   r   r   r   rC   r   gUUUUUU?皙?r   r   hspacewspaceNr   rM   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   r7   r=   r>   r   r?   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.Tr4   r   r   )r   r   皙?r   N)r7   r=   r   add_axesr;   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 gridspecsTr4   r   rT   r   r   r   r   Nr   r!   )r7   r8   rc   rd   r9   r   )r;   rY   r   r   ax3ax4r   r   r   test_constrained_layout173  s   r   c                  C   sV   t jdd\} }| }t| t|dd | j  t| j| jks)J dS )z
Test twinxTr4   r6   r   N)	r7   r=   twinxr   rg   rf   allget_positionextentsr   r   r   r   test_constrained_layout18D  s   
 r   c                  C   sj   t jdd\} }| }t| t|dd |d |d | j  t| j	| j	ks3J dS )z
Test twinyTr4   r6   r   r   N)
r7   r=   twinyr   r   rg   rf   r   r   r   r   r   r   r   test_constrained_layout19N  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    rn   N)r   r   r   r   r!   )r(   linspacehypotr7   r8   r   r,   rF   )gximgr;   r   meshr   r   r   test_constrained_layout20Z  s   r   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 layoutTr4   	Suptitle0	Suptitle1N)r7   r=   rx   rg   rf   r(   copyr   r   testingassert_allcloser;   r   extents0extents1r   r   r   test_constrained_layout21e  s   



r   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 positionedTr4   Suptitler{   r/   N)r7   r=   rg   rf   r(   r   r   r   rx   r   r   r   r   r   r   test_constrained_layout22t  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   T123)r5   clearnumr   r   z
Suptitle{}N)ranger7   r8   rV   rW   rx   format)rr   r;   rY   subr   r   r   test_constrained_layout23  s   r   ztest_colorbar_location.pngT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...
    FrB   rn   r    Tr4   r   Nr   r   )r   rK   r!   r   r{   rP   )r   rK   rR   r   g?)r   rK   rR   rD   r   topr   leftright)r7   r   r=   r>   r3   r   r   rF   rM   r   r   r   test_colorbar_location  s   


 "r   c                  C   sZ   t jdddd\} }|d d | j  t|d  j}tj	j
|g ddd	 d S )
Nr   Tr4   rm   Fr   )g|R?g\	b?g&:?g9?q?h㈵>)rtol)r7   r=   set_visiblerg   rf   r(   r   r   r   r   r   )r;   r@   r   r   r   r   test_hidden_axes  s   


r   c               	   C   sp  dD ]} 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rU|jj	g  |jj
	g  |d |d q|jddddd |j  | dv rt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   rP   r   Tr4   in)	directionr   g{Gz?)r   rR   rK   rD   r   r   gqq?g?r   )r   r   r   r   )r7   r=   rE   r>   tick_paramsr3   rF   r   xaxis	set_ticksyaxisr   r   r   rg   rf   r(   r   r   r   x0y0)rR   r;   r@   cbsrG   r   pccbr   r   r   test_colorbar_align  sF   




r   ztest_colorbars_no_overlapV.pngc                  C   s|   t jddd} | jddddd}|D ]$}|jt  |jddd	 |ddgd
dgg}| j	||dd q| 
d d S )N)r   rn   Trk   r   r   rt   ru   bothr   axisr   r   rn   verticalr   orientationfoo)r7   r8   r=   r   set_major_formatterr   NullFormatterr   imshowrF   rx   r;   r@   r   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 ]$}|jt  |jdd	d
 |	ddgddgg}| j
||dd qd S )N)rn   r   Trk   r   r   r   r   r   r   r   r   rn   
horizontalr   )r7   r8   rx   r=   r   r   r   r   r   r   rF   r   r   r   r   test_colorbars_no_overlapH  s   
r   c                  C   s   t jdddd\} }|d g d | j  |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
 | j  |d  }tj|ddgddgg d S )Nr   r   Tr4   r   )r   r   333333?r   r   r{      )r   g)\(?)r7   r=   set_positionrg   rf   r   r(   r   r   r,   randomrandrF   )r;   r@   ppr   r   r   r   test_manually_set_position  s   

r   ztest_bboxtight.pngbbox_inchestight)r   r   savefig_kwargc                  C      t jdd\} }|d d S NTr4   r#   r7   r=   rw   r:   r   r   r   test_bboxtight  s   r   ztest_bbox.pngr{   g      @r   c                  C   r   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j	 g}t
jj|d j|d jg|d jddd |d jdksoJ 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   r   )r   r   gffffff?)r5   rl   gridspec_kwr   Labelg      g      ?)r@   r   r   )r   atolN)r7   r=   set_ylimr   align_ylabelsrg   rf   r   rz   get_window_extentr(   r   r   r   )r;   r   r   r   after_alignr   r   r   test_align_labels  s(   







r	  c                  C   s  t jdd\} }| j  || j }| d | d | j  || j }|j|jd ks6J |j	|j	d ks@J t jdd\} }| j  || j }| jddd | jddd | j  || j }|j|jd kszJ |j	|j	d ksJ d S )	NTr4   BooBooyg      $@r{   )r0   r   )
r7   r=   rg   rf   get_tightbboxrh   	supxlabel	supylabelr   r   )r;   r   pos0posr   r   r   test_suplabels0  s$   





r  )r   F)r   )5numpyr(   r`   matplotlib.testing.decoratorsr   matplotlib.pyplotpyplotr7   matplotlib.gridspecrc   matplotlib.transforms
transformsmtransforms
matplotlibr   r   r   r3   r<   rA   rH   rN   rS   r^   ri   rs   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Bboxr  r	  r  r   r   r   r   <module>   s    




















 



"