o
    Ďi^                  
   @   sv  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 ejdgZdddZdd	d
Zedgdddd Zedgdddd Zedgdddd Zedgdd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d$d% Zed&gddd'd( Zed)gde  d*krd nd+d,d-d. Z!ed/gddd0d1 Z"ed2gddd3d4 Z#ed5gddd6d7 Z$ed8gddd9d: Z%ed;gddd<d= Z&ed>gddd?d@ Z'edAgdddBdC Z(edDgdddEdF Z)dGdH Z*dIdJ Z+dKdL Z,dMdN Z-dOdP Z.dQdR Z/edSgdTddUdVdW Z0dXdY Z1dZd[ Z2ed\gddd]d^ Z3ed_gddd`da Z4dbdc Z5eddgdTddedfidgdhdi Z6edjgdTddee7dkd gdldmggidgdndo Z8dpdq Z9drds Z:dtdu Z;dvdw Z<dxdy Z=dzd{ Z>d|d} Z?d~d Z@ejAdddi dTfddidTfgdd ZBdd ZCdd ZDdd ZEdS )    N)image_comparison)gridspectickertext_placeholders   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   c/home/jeff/fluffinator/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.pngmpl20)stylec                  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   r6   r7   r9   r   N)r:   subplotsflatr   r>   axsr   r   r   r   test_constrained_layout24   s   
rD   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   r6   r7   r9   r   r	   g{Gz?{Gz?)r   padN)r:   r@   	enumeraterA   r3   colorbar)r>   rC   nnr   r2   rF   r   r   r   test_constrained_layout3<   s   rJ   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   r6   r7   r9   r   {Gz?r   r   rF   shrinkNr:   r@   rA   r3   rH   r>   rC   r   r2   r   r   r   test_constrained_layout4J   s   
rP   zconstrained_layout5.pngc                  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   r6   r7   r9   r   FrK   r   bottom)r   use_gridspecrF   rM   locationNrN   rO   r   r   r   test_constrained_layout5T   s   

rT   zconstrained_layout6.pngc               	   C   s   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}q>| j||d
ddt	j
ddd dS )z,Test constrained_layout for nested gridspecsr6   r7   r   r   r;   r   r   r   zx-label
MultiLinerK   gGz?rQ   r    r
   )r   rF   rM   rS   ticksN)r:   r;   add_gridspecsubgridspecr<   r   r   r3   rH   r   MaxNLocator)r>   gsgslgsraxslr   axsrr2   r   r   r   test_constrained_layout6c   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	   )
r:   r;   rW   rX   ranger<   draw_without_renderingget_positiony0y1)r>   GSGSAGSBaxaaxbir   r   r   test_identical_subgridspec{   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matchr6   r7   r   r   r   N)
pytestwarnsUserWarningr:   r;   r   GridSpecGridSpecFromSubplotSpecr<   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    r6   figsizer8   r	   r    rU   r   r   r   r      	   r    r   NrK   r   rL   )
r:   r;   r   rs   r<   r3   r   r   r   rH   )r>   rZ   rC   jilistrl   r   r2   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   r6   Fr8   sharexshareyr9   r   r|   r   rK   r   rL   zTest Suptitle   N)	r:   r@   rA   r3   r   r   
set_aspectrH   suptitlerO   r   r   r   test_constrained_layout9   s   




r   zconstrained_layout10.pngx86_64gMb?)r5   tolc                  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   r6   r7   r   zThis is a label)labelzcenter left)g?      ?)locbbox_to_anchorN)r:   r@   rA   r   r(   arangelegendrB   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 gridspecsr6   )   r	   r8   rx   r   r   rU   r   r{   r   r        Q@r   rM   aspectN	r:   r;   r   rs   rt   r<   r   r3   rH   r>   gs0r[   gsl0r   rC   rZ   r2   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_ratiosr6   )rv   r	   r   r   r      )r;   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.r6   )r      r   r   r   rU   Nr	   r      r   r   T)r   rz   r   )r:   r;   r   rs   r<   r   r   )r>   r   ax1ax2r   r   r   r   test_constrained_layout12   s   r   zconstrained_layout13.pngc                  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   r6   r7   r   r   r         4@rE   r   rM   r   rF   r   )wpadhpadNUUUUUU?w_padh_pad)
r:   r@   rA   r3   rH   rp   raises	TypeErrorget_layout_enginesetrO   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   r6   r7   r   r   r   r   rE   r   gUUUUUU?皙?r   r   hspacewspaceN)r:   r@   rA   r3   rH   r   r   rO   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)mplrcParamsr:   r@   rA   r   rB   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.r6   r7   r   r   )r   r   皙?r   N)r:   r@   r   add_axesr>   r   r   r   r   r   test_constrained_layout163  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 gridspecsr6   r7   r	   rU   r   r   r   r   Nr   r!   )r:   r;   r   rs   r<   r   )r>   rZ   r   r   ax3ax4r   r   r   test_constrained_layout17;  s   r   c                  C   sT   t jdd\} }| }t| t|dd |   t| j| jks(J dS )z
Test twinxr6   r7   r9   r   N)r:   r@   twinxr   rc   allrd   extentsr   r   r   r   test_constrained_layout18L  s    r   c                  C   sh   t jdd\} }| }t| t|dd |d |d |   t| j| jks2J dS )z
Test twinyr6   r7   r9   r   r|   N)	r:   r@   twinyr   r   rc   r   rd   r   r   r   r   r   test_constrained_layout19V  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hypotr:   r;   r   r,   rH   )gximgr>   r   meshr   r   r   test_constrained_layout20b  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 layoutr6   r7   	Suptitle0	Suptitle1N)
r:   r@   r   rc   r(   copyrd   r   testingassert_allcloser>   r   extents0extents1r   r   r   test_constrained_layout21m  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 positionedr6   r7   Suptitler   r/   N)
r:   r@   rc   r(   r   rd   r   r   r   r   r   r   r   r   test_constrained_layout22|  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   r6   T123)r8   clearnumr   r   r   N)rb   r:   r;   rW   rX   r   )rl   r>   rZ   subr   r   r   test_constrained_layout23  s   r   ztest_colorbar_location.pngT)remove_textr5   c                  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...
    Fzpcolormesh.snaprz   r    r6   r7   r|   Nr   r   )r   rM   r!   r   r   rQ   )r   rM   rS   r   g?)r   rM   rS   rF   r	   topr   leftright)r:   r   r@   rA   r3   r   r   rH   rO   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   r6   r7   ry   Fr   )g/ע?g<Q?gd:tzލ?g`?h㈵>)rtol)
r:   r@   set_visiblerc   r(   r   rd   r   r   r   )r>   rC   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   rQ   r   r6   r7   in)	directionr   g{Gz?)r   rS   rM   rF   r   gqq?g?r   )r   r   r   r	   )r:   r@   rG   rA   tick_paramsr3   rH   r   xaxis	set_ticksyaxisr   r   r   r   rc   r(   r   r   rd   x0re   )rS   r>   rC   cbsrI   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   rz   r6   rw   r   r   Tr   r   bothr   axisr   r	   rz   verticalr   orientationfoo)r:   r;   r@   r   set_major_formatterr   NullFormatterr   imshowrH   r   r>   rC   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   r6   rw   r   r   r   Tr   r   r   r   r	   rz   
horizontalr   )r:   r;   r   r@   r   r   r   r   r   r   rH   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   r6   r7   r   r   r   333333?r  r   r      r   g)\(?)r:   r@   set_positionrc   rd   r(   r   r   r,   randomrandrH   )r>   rC   ppr   r   r   r   test_manually_set_position  s   r  ztest_bboxtight.pngbbox_inchestight)r   r5   savefig_kwargc                  C      t jdd\} }|d d S Nr6   r7   r#   r:   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   r6   )g@r   r   )r   r   gffffff?)r8   rx   gridspec_kwr   Labelg      g      ?)rC   r   r   )r   atolN)r:   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 )	Nr6   r7   BooBooyg      $@r   )r0   r   )
r:   r@   rc   get_tightbboxcanvasget_renderer	supxlabel	supylabelre   r   )r>   r   pos0posr   r   r   test_suplabels6  s$   

r&  c                  C   s:   t  } | dd}| |dd dd f }|   d S )Nr	   r   r   )r:   r;   rW   r<   rc   )r>   rZ   spr   r   r   test_gridspec_addressingM  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   rE   r   )r:   r@   rc   rp   rq   PendingDeprecationWarningset_constrained_layoutr=   r   r   r   test_discouraged_apiT  s    


"r+  c                  C   s    t jddid\} }|   d S )Nr   rE   r`   )r:   r@   rc   r=   r   r   r   test_kwargse  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 )Nr6   r7   )r   r   r   r   )rectr   r  r   )
r:   r@   r   r   rc   rd   x1rf   r   re   )r>   r   pposr   r   r   	test_rectj  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   gz?rK   r  ry   gz?MbP?)r    rz   )r8   r   r   rx   gZ|
?g+ݓ?)r   r   g\C?gMSt$?)r:   r@   rA   r   r(   r	  randnrH   rc   rd   r   r   r   r.  rf   re   )r>   rC   r   r   r%  r   r   r   test_compressed1|  s0   


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

r5  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   r8   r  equalr   r   r   g-?r3  )absg\(\?r   F)	in_layout)	r:   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`   )r:   r@   get_constrained_layout)argstater>   r   r   r   r   test_set_constrained_layout  s   rB  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)r:   r@   rp   rq   r)  r*  r?  r=   r   r   r   test_constrained_toggle  s   


"rC  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>)	r:   r;   r<   rc   closegccollectanyget_objects)r>   r   r   r   test_layout_leak  s   
rO  c                  C   s   t jddd} | dd}g }| D ].}|dd}tdD ]}||||df g7 }|d   q||d	d	df   q|   |dd	 D ]}t	j
| jd |d  jd d
dsdJ qLd	S )z
    Test that the submerged margin logic does not get called multiple times
    on same axes if it is already in a subfigure
    )rz   r    r6   rw   r	   r   r   r   r!   Ngư>r2  )r:   r;   
subfiguresflattenrW   rb   r<   r   rc   r(   allcloserd   bounds)r>   figuresrC   frZ   rl   r   r   r   r   test_submerged_subfig  s   rV  )r   F)r   )FrK  platformnumpyr(   rp   
matplotlibr   matplotlib.testing.decoratorsr   matplotlib.pyplotpyplotr:   matplotlib.transforms
transformsmtransformsr   r   markusefixtures
pytestmarkr   r3   r?   rD   rJ   rP   rT   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  r5  r>  parametrizerB  rC  rO  rV  r   r   r   r   <module>   s    






	














 



"

