o
    i2                     @   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mZ dYddZdZd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 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j'(dNej'j)dOdPedQgdRdSdTdUdV Z*dWdX Z+dS )[    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   b/var/www/edux/Edux_v2/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      g      ?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} | d}t|dd dS )z,Test constrained_layout for a single subplotTconstrained_layouto      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   Tr3   r6   r   N)r7   subplotsflatr   r:   axsr   r   r   r   test_constrained_layout2+   s   
r@   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   Tr3   r6   r   r   g{Gz?{Gz?)r   padN)r7   r<   	enumerater=   r2   colorbar)r:   r?   nnr   r1   rB   r   r   r   test_constrained_layout33   s   rF   constrained_layout4c                  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   Tr3   r6   r   {Gz?r   r   rB   shrinkNr7   r<   r=   r2   rD   r:   r?   r   r1   r   r   r   test_constrained_layout4@   s   
rM   zconstrained_layout5.pngg?)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   Tr3   r6   r   FrH   r   bottom)r   use_gridspecrB   rJ   locationNrK   rL   r   r   r   test_constrained_layout5I   s   

rR   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 gridspecsTr3   r   r   r8   r   r   r   zx-label
MultiLinerH   gGz?rO   r    r	   )r   rB   rJ   rQ   ticksN)r7   r8   add_gridspecsubgridspecr9   r   r   r2   rD   r   MaxNLocator)r:   gsgslgsraxslr   axsrr1   r   r   r   test_constrained_layout6W   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 GridSpeczPCalling figure.constrained_layout, but figure not setup to do constrained layout)matchTr3   r   r   r   N)pytestwarnsUserWarningr7   r8   gridspecGridSpecGridSpecFromSubplotSpecr9   drawcanvasget_renderer)r:   rX   rY   rZ   r   r   r   test_constrained_layout7o   s   "rh   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    T)figsizer4   r   r    rS   r   r   r   r      	   r   r   r   NrH   r   rI   )
r7   r8   rb   rc   r9   r2   r   r   r   rD   )r:   rX   r?   jilistir   r1   r   r   r   test_constrained_layout8~   s*   


	
rq   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)r4   sharexshareyr6   r   r   r   rH   r   rI   zTest Suptitle   N)	r7   r<   r=   r2   r   r   
set_aspectrD   suptitlerL   r   r   r   test_constrained_layout9   s   




rw   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   Tr3   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 gridspecsT)   r   r4   rj   r   r   rS   r   rm   r   r        Q@r   rJ   aspectN	r7   r8   rb   rc   rd   r9   r   r2   rD   r:   gs0rY   gsl0r   r?   rX   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_ratiosT)ri   r   r   r   r      )r8   width_ratiosr   )height_ratiosrm   r   r   r   r   Nr   r   r   r   r   test_constrained_layout11rat   s   

r   zconstrained_layout12.pngc                  C   s   t j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.Tr3   r   r   rS   Nr   r   r6   r   r   )r   rl   r   )r7   r8   rb   rc   r9   r   r   )r:   r   ax1ax2r   r   r   r   test_constrained_layout12   s   r   zconstrained_layout13.pngrA   c                  C   sR   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.r   Tr3   r   r   r         4@rA   r   rJ   r   rB   gUUUUUU?)w_padh_padNr7   r<   r=   r2   rD   set_constrained_layout_padsrL   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   Tr3   r   r   r   r   rA   r   gUUUUUU?皙?)r   r   hspacewspaceNr   rL   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.Tr3   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 gridspecsTr3   r   rS   r   r   r   r   Nr   r!   )r7   r8   rb   rc   r9   r   )r:   rX   r   r   ax3ax4r   r   r   test_constrained_layout17  s   r   c                  C   sV   t jdd\} }| }t| t|dd | j  t| j| jks)J dS )z
Test twinxTr3   r6   r   N)	r7   r<   twinxr   rf   re   allget_positionextentsr   r   r   r   test_constrained_layout18$  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 twinyTr3   r6   r   r   N)
r7   r<   twinyr   r   rf   re   r   r   r   r   r   r   r   test_constrained_layout19.  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    rl   N)r   r   r   r   r!   )r'   linspacehypotr7   r8   r   r+   rD   )gximgr:   r   meshr   r   r   test_constrained_layout20:  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 layoutTr3   	Suptitle0	Suptitle1N)r7   r<   rv   rf   re   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 positionedTr3   Suptitlery   )r.   N)r7   r<   rf   re   r'   r   r   r   rv   r   r   r   r   r   r   test_constrained_layout22T  s   

r   c                  C   s6   t dD ]} tj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   123T)numr4   clearz
Suptitle{}N)ranger7   r<   rv   format)rp   r:   r   r   r   r   test_constrained_layout23b  s   r      r   )rerunsztest_colorbar_location.pngTmpl20)remove_textstylec                  C   s   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 | 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...
    rl   r    Tr3   r   Nr   r   )r   rJ   r!   r   ry   rO   )r   rJ   rQ   r   r   topr   leftright)r7   r<   r=   r2   r   r   rD   rL   r   r   r   test_colorbar_locationp  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   Tr3   rk   Fr   )g|R?gAF?gԲH?g9?q?gh㈵>)rtol)r7   r<   set_visiblerf   re   r'   r   r   r   r   r   )r:   r?   r   r   r   r   test_hidden_axes  s   


r   )r   F)r   ),numpyr'   r_   matplotlib.testing.decoratorsr   matplotlib.pyplotpyplotr7   matplotlib.gridspecrb   
matplotlibr   r   r   r2   r;   r@   rF   rM   rR   r]   rh   rq   rw   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   marktimeoutflakyr   r   r   r   r   r   <module>   sp    














	





