o
    tBhL                  
   @   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 dtddZdud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ddRdSd[d\ Z.ed]gddRdSd^d_ Z/d`da Z0edbgdQdRdcddidedfdg Z1edhgdQdRdce2did gdjdkggidedldm Z3dndo Z4dpdq Z5drds Z6dS )v    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 | 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/riverr-enterprise-integrations-main/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 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   Tr3   r5   r   N)r6   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   r5   r   r   g{Gz?{Gz?)r   padN)r6   r<   	enumerater=   r2   colorbar)r:   r?   nnr   r1   rB   r   r   r   test_constrained_layout34   s   rF   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   Tr3   r5   r   {Gz?r   r   rB   shrinkNr6   r<   r=   r2   rD   r:   r?   r   r1   r   r   r   test_constrained_layout4B   s   
rL   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   Tr3   r5   r   FrG   r   bottom)r   use_gridspecrB   rI   locationNrJ   rK   r   r   r   test_constrained_layout5L   s   

rQ   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.snapTr3   r   r   r7   r   r   r   zx-label
MultiLinerG   gGz?rN   r   r	   )r   rB   rI   rP   ticksN)r6   r   r7   add_gridspecsubgridspecr8   r   r   r2   rD   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 )NTr3   r   r   r   r   )
r6   r7   rU   rV   ranger8   draw_without_renderingget_positiony0y1)r:   GSGSAGSBaxaaxbir   r   r   test_identical_subgridspecv   s   $ri   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matchTr3   r   r   r   N)
pytestwarnsUserWarningr6   r7   gridspecGridSpecGridSpecFromSubplotSpecr8   r_   )r:   rX   rY   rZ   r   r   r   test_constrained_layout7   s   
"rr   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   NrG   r   rH   )
r6   r7   ro   rp   r8   r2   r   r   r   rD   )r:   rX   r?   jilistrh   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   TF)r4   sharexshareyr5   r   ry   r   rG   r   rH   zTest Suptitle   N)	r6   r<   r=   r2   r   r   
set_aspectrD   suptitlerK   r   r   r   test_constrained_layout9   s   




r   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)r6   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   ru   r   r   rS   r   rx   r   r        Q@r   rI   aspectN	r6   r7   ro   rp   rq   r8   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)rs   r   r   r   r      )r7   width_ratiosr   )height_ratiosrx   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   rS   Nr   r      r   r   )r   rw   r   )r6   r7   ro   rp   r8   r   r   )r:   r   ax1ax2r   r   r   r   test_constrained_layout12   s   r   zconstrained_layout13.pngrA   c                  C   s   t jdddd\} }|jD ]}t|dd}| j||dddd	 qtjtd
d | jddd W d   n1 s9w   Y  | jddd dS )Test that padding works.r   Tr3   r   r   r         4@rA   r   rI   r   rB   zunexpected keyword argumentrj   r   )wpadhpadNgUUUUUU?)w_padh_pad)	r6   r<   r=   r2   rD   rl   raises	TypeErrorset_constrained_layout_padsrK   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wspaceN)r6   r<   r=   r2   rD   r   rK   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   r6   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)r6   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    )r6   r7   ro   rp   r8   r   )r:   rX   r   r   ax3ax4r   r   r   test_constrained_layout175  s   r   c                  C   sT   t jdd\} }| }t| t|dd |   t| j| jks(J dS )z
Test twinxTr3   r5   r   N)r6   r<   twinxr   r_   allr`   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s2J dS )z
Test twinyTr3   r5   r   ry   N)	r6   r<   twinyr   r   r_   r   r`   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   rw   N)r   r   r   r   r    )r'   linspacehypotr6   r7   r   r+   rD   )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 layoutTr3   	Suptitle0	Suptitle1N)
r6   r<   r   r_   r'   copyr`   r   testingassert_allcloser:   r   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 positionedTr3   Suptitler   r.   N)
r6   r<   r_   r'   r   r`   r   r   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   T123)r4   clearnumr   r   z
Suptitle{}N)r^   r6   r7   rU   rV   r   format)rh   r:   rX   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...
    FrR   rw   r   Tr3   ry   Nr   r   )r   rI   r    r   r   rN   )r   rI   rP   r   g?)r   rI   rP   rB   r   topr   leftright)r6   r   r<   r=   r2   r   r   rD   rK   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   Tr3   rv   Fr   )g|R?g\	b?g&:?g9?q?h㈵>)rtol)
r6   r<   set_visibler_   r'   r   r`   r   r   r   )r:   r?   r   r   r   r   test_hidden_axes  s   

r   c               	   C   sn  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   rN   r   Tr3   in)	directionr   g{Gz?)r   rP   rI   rB   r   gqq?g?r   )r   r   r   r   )r6   r<   rC   r=   tick_paramsr2   rD   r   xaxis	set_ticksyaxisr   r   r   r_   r'   r   r   r`   x0ra   )rP   r:   r?   cbsrE   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   rw   Trt   r   r   r}   r~   bothr   axisr   r   rw   verticalr   orientationfoo)r6   r7   r<   r   set_major_formatterr   NullFormatterr   imshowrD   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)rw   r   Trt   r   r   r   r   r   r   r   r   rw   
horizontalr   )r6   r7   r   r<   r   r   r   r   r   r   rD   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   Tr3   r   )r   r   333333?r   r   r      )r   g)\(?)r6   r<   set_positionr_   r`   r'   r   r   r+   randomrandrD   )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 NTr3   r"   r6   r<   r   r9   r   r   r   test_bboxtight  s   r	  ztest_bbox.pngr   g      @r   c                  C   r  r  r  r9   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   T)g@r   r   )r   r   gffffff?)r4   ru   gridspec_kwr   Labelg      g      ?)r?   r   r   )r   atolN)r6   r<   set_ylimr   align_ylabelsr_   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 )	NTr3   BooBooyg      $@r   )r/   r   )
r6   r<   r_   get_tightbboxcanvasget_renderer	supxlabel	supylabelra   r   )r:   r   pos0posr   r   r   test_suplabels2  s$   

r  c                  C   s:   t  } | dd}| |dd dd f }|   d S )Nr   r   r   )r6   r7   rU   r8   r_   )r:   rX   spr   r   r   test_gridspec_addressingI  s   r  )r   F)r   )7numpyr'   rl   matplotlib.testing.decoratorsr   matplotlib.pyplotpyplotr6   matplotlib.gridspecro   matplotlib.transforms
transformsmtransforms
matplotlibr   r   r   r2   r;   r@   rF   rL   rQ   r]   ri   rr   r|   r   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   r   <module>   s    





	














 



"