o
    hx[                  
   @   s*  d dl Z d dlZ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 dddZdd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e d)krd nd*dd+d, Zed-gd.d/ Zed0gd1d2 Z ed3gd4d5 Z!ed6gd7dd8d9 Z"ed:gd;d< Z#ed=gd>d? Z$ed@gdAdB Z%edCgdDdE Z&dFdG Z'dHdI Z(dJdK Z)dLdM Z*dNdO Z+dPdQ Z,edRgdSdTdUdVdW Z-dXdY Z.dZd[ Z/ed\gdTd]d^d_ Z0ed`gdTd]dadb Z1dcdd Z2edegdSdTdfdgidhdidj Z3edkgdSdTdfe4dld gdmdnggidhdodp Z5dqdr Z6dsdt Z7dudv Z8dwdx Z9dydz Z:d{d| Z;d}d~ Z<dd Z=ej>?dddi dSfddidSfgdd Z@dd ZAdd ZBdS )    N)image_comparison)gridspecticker   Fc                 C   sd   |  ddg | jdd |s&| jd|d | jd|d | jd|d d S | g  | g  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   {/var/www/html/construction_image-detection-poc/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 r2   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   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   r3   r4   r6   r   N)r7   subplotsflatr   r;   axsr   r   r   r   test_constrained_layout2/   s   
rA   zconstrained_layout3.pngc                  C   sZ   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 subplotsr   r3   r4   r6   r   r   g{Gz?{Gz?)r   padN)r7   r=   	enumerater>   r2   colorbar)r;   r@   nnr   r1   rC   r   r   r   test_constrained_layout37   s   rG   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   r3   r4   r6   r   {Gz?r   r   rC   shrinkNr7   r=   r>   r2   rE   r;   r@   r   r1   r   r   r   test_constrained_layout4E   s   
rM   zconstrained_layout5.pnggMb`?)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   r3   r4   r6   r   FrH   r   bottom)r   use_gridspecrC   rJ   locationNrK   rL   r   r   r   test_constrained_layout5O   s   

rR   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 gridspecsFpcolormesh.snapr3   r4   r   r   r8   r   r   r   zx-label
MultiLinerH   gGz?rO   r   r	   )r   rC   rJ   rQ   ticksN)r7   rcParamsr8   add_gridspecsubgridspecr9   r   r   r2   rE   r   MaxNLocator)r;   gsgslgsraxslr   axsrr1   r   r   r   test_constrained_layout6^   s(   







r_   c                  C   s   t jdd} | dd}|d dd}|d dd}g }g }tdD ]}|| || g7 }|| || g7 }q$|   |d  j|d  j	ksOJ d S )NTconstrained_layoutr   r   r   r   )
r7   r8   rW   rX   ranger9   draw_without_renderingget_positiony0y1)r;   GSGSAGSBaxaaxbir   r   r   test_identical_subgridspecy   s   $rm   c                  C   s   t jtdd5 tjdd} tdd}tdd|d }tdd|d }|D ]}| | q(| 	  W d   dS 1 s?w   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matchr3   r4   r   r   r   N)
pytestwarnsUserWarningr7   r8   r   GridSpecGridSpecFromSubplotSpecr9   rc   )r;   rZ   r[   r\   r   r   r   test_constrained_layout7   s   
"ru   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 ]-}| |||f }||g7 }t|dd |dkrB|d |d	k rK|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 full)
   r   r3   figsizer5   r   r   rT   r   r   r   r      	   r    r   NrH   r   rI   )
r7   r8   r   rs   r9   r2   r   r   r   rE   )r;   rZ   r@   jilistrl   r   r1   r   r   r   test_constrained_layout8   s*   


	
r   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   r3   Fr5   sharexshareyr6   r   r|   r   rH   r   rI   zTest Suptitle   N)	r7   r=   r>   r2   r   r   
set_aspectrE   suptitlerL   r   r   r   test_constrained_layout9   s   




r   zconstrained_layout10.pngx86_64gMb?c                  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   r3   r4   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   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	}q2| j||d
dd | |d }t|dd	 dS )z"Test for multiple nested gridspecsr3   )   r   r5   rx   r   r   rT   r   r{   r   r        Q@r   rJ   aspectN	r7   r8   r   rs   rt   r9   r   r2   rE   r;   gs0r[   gsl0r   r@   rZ   r1   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}q9| j||ddd | |d }t|d
d dS )z4Test for multiple nested gridspecs with width_ratiosr3   )rv   r   r   r   r      )r8   width_ratiosr   )height_ratiosr{   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.r3   )r      r   r   r   rT   Nr   r      r   r   T)r   rz   r   )r7   r8   r   rs   r9   r   r   )r;   r   ax1ax2r   r   r   r   test_constrained_layout12   s   r   zconstrained_layout13.pngrB   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 s9w   Y  |  j	ddd dS )Test that padding works.r   r3   r4   r   r   r         4@rB   r   rJ   r   rC   r   )wpadhpadNUUUUUU?w_padh_pad)
r7   r=   r>   r2   rE   rp   raises	TypeErrorget_layout_enginesetrL   r   r   r   test_constrained_layout13  s   
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   r3   r4   r   r   r   r   rB   r   gUUUUUU?皙?r   r   hspacewspaceN)r7   r=   r>   r2   rE   r   r   rL   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)mplrV   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.r3   r4   r   r   )r   r   皙?r   N)r7   r=   r   add_axesr;   r   r   r   r   r   test_constrained_layout161  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 gridspecsr3   r4   r   rT   r   r   r   r   Nr   r    )r7   r8   r   rs   r9   r   )r;   rZ   r   r   ax3ax4r   r   r   test_constrained_layout179  s   r   c                  C   sT   t jdd\} }| }t| t|dd |   t| j| jks(J dS )z
Test twinxr3   r4   r6   r   N)r7   r=   twinxr   rc   allrd   extentsr   r   r   r   test_constrained_layout18J  s    r   c                  C   sh   t jdd\} }| }t| t|dd |d |d |   t| j| jks2J dS )z
Test twinyr3   r4   r6   r   r|   N)	r7   r=   twinyr   r   rc   r   rd   r   r   r   r   r   test_constrained_layout19T  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   rz   N)r   r   r   r   r    )r'   linspacehypotr7   r8   r   r+   rE   )gximgr;   r   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 layoutr3   r4   	Suptitle0	Suptitle1N)
r7   r=   r   rc   r'   copyrd   r   testingassert_allcloser;   r   extents0extents1r   r   r   test_constrained_layout21k  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 positionedr3   r4   Suptitler   r.   N)
r7   r=   rc   r'   r   rd   r   r   r   r   r   r   r   r   test_constrained_layout22z  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   r3   T123)r5   clearnumr   r   r   N)rb   r7   r8   rW   rX   r   )rl   r;   rZ   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...
    FrS   rz   r   r3   r4   r|   Nr   r   )r   rJ   r    r   r   rO   )r   rJ   rQ   r   g?)r   rJ   rQ   rC   r   topr   leftright)r7   rV   r=   r>   r2   r   r   rE   rL   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   r3   r4   ry   Fr   )g|R?g\	b?g&:?g9?q?h㈵>)rtol)
r7   r=   set_visiblerc   r'   r   rd   r   r   r   )r;   r@   r   r   r   r   test_hidden_axes  s   

r   c               	   C   sr  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  |g  |g  q| jddddd |  | 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   rO   r   r3   r4   in)	directionr   g{Gz?)r   rQ   rJ   rC   r   gqq?g?r   )r   r   r   r   )r7   r=   rD   r>   tick_paramsr2   rE   r   xaxis	set_ticksyaxisr   r   r   r   rc   r'   r   r   rd   x0re   )rQ   r;   r@   cbsrF   r   pccbr   r   r   test_colorbar_align  sF   


r   ztest_colorbars_no_overlapV.png)r   c                  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   rz   r3   rw   r   r   Tr   r   bothr   axisr   r   rz   verticalr   orientationfoo)r7   r8   r=   r   set_major_formatterr   NullFormatterr   imshowrE   r   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)rz   r   r3   rw   r   r   r   Tr   r   r   r   r   rz   
horizontalr   )r7   r8   r   r=   r   r   r   r   r   r   rE   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   r3   r4   r   r   r   333333?r  r   r      r   g)\(?)r7   r=   set_positionrc   rd   r'   r   r   r+   randomrandrE   )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 Nr3   r4   r"   r7   r=   r   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 g}t	j
j|d j|d jg|d jddd |d jdksnJ 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   r3   )g@r   r   )r   r   gffffff?)r5   rx   gridspec_kwr   Labelg      g      ?)r@   r   r   )r   atolN)r7   r=   set_ylimr   align_ylabelsrc   r   r   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 }| d | d |   || j }|j|jd ks4J |j	|j	d ks>J t jdd\} }|   || j }| jddd | jddd |   || j }|j|jd ksvJ |j	|j	d ksJ d S )	Nr3   r4   BooBooyg      $@r   )r/   r   )
r7   r=   rc   get_tightbboxcanvasget_renderer	supxlabel	supylabelre   r   )r;   r   pos0posr   r   r   test_suplabels4  s$   

r&  c                  C   s:   t  } | dd}| |dd dd f }|   d S )Nr   r   r   )r7   r8   rW   r9   rc   )r;   rZ   spr   r   r   test_gridspec_addressingK  s   r(  c                  C   s   t jdd\} }|   tjtdd t  \} }| d |   W d    n1 s-w   Y  tjtdd t  \} }| ddd |   W d    d S 1 sWw   Y  d S )NTr`   zwill be deprecatedrn   rB   r   )r7   r=   rc   rp   rq   PendingDeprecationWarningset_constrained_layoutr:   r   r   r   test_discouraged_apiR  s    


"r+  c                  C   s    t jddid\} }|   d S )Nr   rB   r`   )r7   r=   rc   r:   r   r   r   test_kwargsc  s   r,  c                  C   s   t jdd\} }|  jg dd |   | }|jdk s!J |jdk s(J t jdd\} }|  jg dd |   | }|jdk sIJ |jdk sPJ |jdksWJ |j	dks^J d S )Nr3   r4   )r   r   r   r   )rectr   r  r   )
r7   r=   r   r   rc   rd   x1rf   r   re   )r;   r   pposr   r   r   	test_recth  s   r0  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}qW| 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   
compressedTr   r  r  r   gX ?MbP?)r  ry   gz?)r   rz   )r5   r   r   rx   gGr鷯?gQ?)r   r   gk+ݓ?goT?)r7   r=   r>   r   r'   r	  randnrE   rc   rd   r   r   r   r.  rf   re   )r;   r@   r   r   r%  r   r   r   test_compressed1z  s0   





r4  c                  C   s   t jddddddd\} \}}|d |d	 |d |d
 | d}|   | d
 tjdddks<J | jddd}|   | d
 dksQJ | jddd}|   | d
 dksfJ d S )Nr   )rz   rv   r1  )g      ?g      ?r   )r   r   )nrowsrx   r5   r  equalr   r   r   g??r2  )absg\(\?r   F)	in_layout)	r7   r=   r   set_box_aspectr   rc   rd   rp   approx)r;   ax0r   titler   r   r   test_compressed_suptitle  s"   




r=  z
arg, state)TT)FFr-  c                 C   s$   t j| d\}}| |u sJ d S )Nr`   )r7   r=   get_constrained_layout)argstater;   r   r   r   r   test_set_constrained_layout  s   rA  c                  C   s~   t  \} }tt* | d |  sJ | d |  r"J | d |  s-J W d    d S 1 s8w   Y  d S )NTF)r7   r=   rp   rq   r)  r*  r>  r:   r   r   r   test_constrained_toggle  s   


"rB  c                  C   sP   t jddd} |   |   t d ~ t  tdd t D r&J d S )NT)rv   rv   )ra   rx   r   c                 s   s    | ]
}t |tjjV  qd S )N)
isinstancer   _layoutgrid
LayoutGrid).0objr   r   r   	<genexpr>  s    z#test_layout_leak.<locals>.<genexpr>)	r7   r8   r9   rc   closegccollectanyget_objects)r;   r   r   r   test_layout_leak  s   
rN  )r   F)r   )CrJ  platformnumpyr'   rp   
matplotlibr   matplotlib.testing.decoratorsr   matplotlib.pyplotpyplotr7   matplotlib.transforms
transformsmtransformsr   r   r   r2   r<   rA   rG   rM   rR   r_   rm   ru   r   r   machiner   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,  r0  r4  r=  markparametrizerA  rB  rN  r   r   r   r   <module>   s    





	














 



"

