o
    h1                     @   s  d dl Z d dlZd dlmZ d dlZd dlZd dlm	Z	 d dl
mZ d dlmZmZ d dlmZ dSddZe	d	gd
ddd Ze	dgdd Ze	dgdd Ze	dgddd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e	d'gd(d) Zd*d+ ZdTd/d0Ze	d1d2gd3d4 Zd5d6 Zej !d7d8d9gd:d; Z"d<d= Z#d>d? Z$d@dA Z%dBdC Z&dDdE Z'ej (dFdGdH Z)dIdJ Z*dKdL Z+dMdN Z,dOdP Z-dQdR Z.dS )U    N)assert_array_equal)image_comparison)AnchoredOffsetboxDrawingArea)	Rectangle   c                 C   sH   |  ddg | jdd | jd|d | jd|d | jd|d d S )	N         nbinsx-labelfontsizey-labelTitle)plotlocator_params
set_xlabel
set_ylabel	set_title)axr    r   u/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/matplotlib/tests/test_tightlayout.pyexample_plot   s
   r   tight_layout1gffffff?)tolc                  C   s$   t  \} }t|dd t   dS )z'Test tight_layout for a single subplot.   r   Npltsubplotsr   tight_layoutfigr   r   r   r   test_tight_layout1   s   r$   tight_layout2c                  C   sJ   t jddd\} \\}}\}}t| t| t| t| t   dS )(Test tight_layout for multiple subplots.r	   )nrowsncolsNr   )r#   ax1ax2ax3ax4r   r   r   test_tight_layout2   s   r-   tight_layout3c                  C   sB   t d} t d}t d}t|  t| t| t   dS )r&         z   N)r   subplotr   r!   )r)   r*   r+   r   r   r   test_tight_layout3)   s   


r3   tight_layout4)z2.5.5z2.6.1Q?)freetype_versionr   c                  C   sj   t dd} t jdddd}t jddddd}t jdddd	}t|  t| t| t| t   d
S )z#Test tight_layout for subplot2grid.)r
   r
   r   r   )r   r   r	   )colspan)r   r   r8   rowspan)r   r	   )r:   N)r   subplot2gridr   r!   )r)   r*   r+   r,   r   r   r   test_tight_layout45   s   r<   tight_layout5c                  C   s2   t  } tdd}| j|dd t   dS )zTest tight_layout for image.d   
   r@   none)interpolationN)r   r2   nparangereshapeimshowr!   )r   arrr   r   r   test_tight_layout5D   s   rH   tight_layout6c            	   	   C   s`  t   t dt t } tjdd}| 	|d }| 	|d }t
| t
| |j| g dd tjdd}|D ]}| 	|}t
| |d |d q>|jd	d
d |j| g ddd t|j|j}t|j|j}|j| dd||j  dd|j|  gd |j| dd||j  dd|j|  gdd W d   dS 1 sw   Y  dS )zTest tight_layout for gridspec.ignorer	   r   r   )r   r         ?r   rectr
    r   r   r   )rK   r   r   r   g?)rM   h_padNrK   )warningscatch_warningssimplefilterUserWarningr   figuremplgridspecGridSpecadd_subplotr   r!   r   r   mintopmaxbottom)	r#   gs1r)   r*   gs2ssr   rZ   r\   r   r   r   test_tight_layout6M   s8   


"r`   tight_layout7c                  C   sr   d} t  \}}|ddg |jdd |jd| d |jd| d |jd	d
| d |jdd| d t   d S )Nr   r   r	   r
   r   r   r   r   z
Left Titleleft)locr   zRight Titleright)r   r    r   r   r   r   r   r!   )r   r#   r   r   r   r   test_tight_layout7w   s   re   tight_layout8{Gzt?c                  C   s6   t  } | jddd |  }t|dd |   dS )#Test automatic use of tight_layout.tight皙?)layoutpadr   r   N)r   rT   set_layout_enginerX   r   draw_without_renderingr"   r   r   r   test_tight_layout8   s
   ro   tight_layout9c                  C   s.   t dd\} }|d d d t   d S )Nr	   r   F)r   r    set_visibler!   )faxarrr   r   r   test_tight_layout9   s   rt   c                  C   s  t  } | d}|jjdddd |jjdddd |jjdddddd	 |jjdddddd	 |jjd
gdd |jjd
gdd | d}|jjdddd |jjdddd | d}|jjdddd |jjdddd | d}|jjdddd |jjdddd t   ddgddggddgddggddgddggddgddggg}t| j	D ]\}}t
t|  d||  qdS )rh   r/   out   r
   )tickdirlengthwidth    Tminor)rw   rx   ry   tick1Onwhichr   )r{      inr0   inout   gK?gCl?gʡE?gB`"?gI+?g/$?gQ?gm?N)r   rT   rX   xaxisset_tick_paramsyaxis	set_ticksr!   	enumerateaxesr   rC   roundget_position
get_points)r#   r   expectednnr   r   r   test_outward_ticks   s@   





r   r@   rj   blackc              
   C   s   |d| }}| | f| df| |f|dfd|f||fd| f|| fd| fg	}|D ](}t ||}td|||dddd}	||	 td|d	d|| jd	d
}
| |
 q-|
S )z&
    Surround ax with OffsetBoxes
    r   rK   r7   Noner   F)ry   height	facecolor	edgecolor	linewidthantialiasedcenterg        )rc   childrl   frameonbbox_to_anchorbbox_transform	borderpad)r   r   
add_artistr   	transAxes)r   sizemargincolormmpanchor_pointspointda
backgroundanchored_boxr   r   r   add_offsetboxes   s4   

r   tight_layout_offsetboxes1tight_layout_offsetboxes2c                     s   d g d ddg  fdd} |  }t   |  }|d d  D ]}| D ]}t|tr=|d q1q+t   d S )Nr	   )redbluegreenyellowr   r   c                     sL   t \} }|j}t| D ]\}}|j|d t|d|d q|S )N)r      )r   r    flatzipr   r   )_axsr   r   colorscolsrowsxyr   r   	_subplots   s   z0test_tight_layout_offsetboxes.<locals>._subplotsF)r   r!   get_children
isinstancer   rq   )r   r   r   r   r   r   r   test_tight_layout_offsetboxes   s   	

r   c                  C   s   t  } |   dS )zETest that tight layout doesn't cause an error when there are no Axes.N)r   gcfr!   )r#   r   r   r   test_empty_layout  s   r   labelxlabelylabelc                 C   s(   t jdd\}}|jdi | di dS )z8Test that no warning emitted when xlabel/ylabel too big.r
   r	   figsizedaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaNr   )r   r    set)r   r#   r   r   r   r   test_verybig_decorators  s   r   c                  C   s4   t jdddd\} }|d d |d d dS )	z+Test that doesn't warn when xlabel too big.r   r	   r   r   r   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbN)r   r    r   r#   r   r   r   r   test_big_decorators_horizontal     r   c                  C   s4   t jdddd\} }|d d |d d dS )	z+Test that doesn't warn when ylabel too big.r	   r   r   r   r   aaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbN)r   r    r   r   r   r   r   test_big_decorators_vertical  r   r   c                   C   sV   t dd t jddddd tt t   W d    d S 1 s$w   Y  d S )N)      r7   )r   r   )r   r
   r
   r   r9   )r   r;   pytestwarnsrS   r!   r   r   r   r   test_badsubplotgrid  s
   
"r   c                  C   s   t jdd\} }|ddg |ddg |jddddd	 | }tt t 	  | }|j
|j
ks9J W d    n1 sCw   Y  tt t j	g d
d W d    d S 1 saw   Y  d S )NTr!   r   r   zBIG LONG STRING)g      ?r	   )g      %@g      ?F)xyxytextannotation_clip)r   r   皙?r   rL   )r   r    set_xlimset_ylimannotater   r   r   rS   r!   ry   )r#   r   p1p2r   r   r   test_collapsed%  s   
"r   c                  C   sJ   t jdd\} }| d}|d}| j  | j| jks#J d S )NTr   foobar)	r   r    suptitler   canvasdrawget_window_extenty0y1)r#   r   sttr   r   r   test_suptitle:  s
   


r   pdfc                    s@   t jjj  fdd}| t jjd| t \}}|  d S )Nc                    s.   t | tjjjs
J  | g|R i | d S )N)r   rU   backendsbackend_pdfRendererPdf)selfargskwargsunpatched_initr   r   __init__F  s   z'test_non_agg_renderer.<locals>.__init__r   )rU   backend_basesRendererBaser   setattrr   r    r!   )monkeypatchrecwarnr   r#   r   r   r   r   test_non_agg_rendererB  s
   
r   c                  C   s   t dd\} }|d jddgddgddgd}|d  }| |jd |jd|jg}| j||d t	j
td	d
 |   W d    d S 1 sJw   Y  d S )Nr   r	   r   r   )crg   r5   )caxzThis figure includes Axesmatch)r   r    scatterr   add_axesx1r   r   colorbarr   r   rS   r!   )r#   r   ptsax_rectr   r   r   r   test_manual_colorbarQ  s    
"r  c            	      C   s   t dd} tjdd}|jddd}|jdd	d}|jd
dd}|||fD ]H}|d || d d df \}|| }|	 sFJ |	 sLJ t
ddd|jd}|| || |  |	 rjJ |	 rpJ q(d S )Nr>   r?   )   r	   r      rectilinear)
projection   	mollweide   polarFr   r7   rK   )	transform)rC   rD   rE   r   rT   rX   gridr   pcolor_fully_clipped_to_axesr   r   set_clip_pathget_pathget_transform)	rG   r#   r)   r*   r+   r   hr   rM   r   r   r   test_clipped_to_axes^  s"   


r  c                  C   sT   t  \} }tjtdd | ddi W d    n1 sw   Y  |   d S )Nzwill be deprecatedr   rl   333333?)r   r    r   r   PendingDeprecationWarningset_tight_layoutrn   r"   r   r   r   test_tight_padsv  s   r  c                  C   s    t jddid\} }|   d S )Nrl   r  r   )r   r    rn   r"   r   r   r   test_tight_kwargs~  s   r  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    r   r   r  r  get_tight_layoutr"   r   r   r   test_tight_toggle  s   


"r  )r   )r@   rj   r   )/rP   numpyrC   numpy.testingr   r   
matplotlibrU   matplotlib.testing.decoratorsr   matplotlib.pyplotpyplotr   matplotlib.offsetboxr   r   matplotlib.patchesr   r   r$   r-   r3   r<   rH   r`   re   ro   rt   r   r   r   r   markparametrizer   r   r   r   r   r   backendr   r  r  r  r  r  r   r   r   r   <module>   sb    







)

	

#

'
	

