o
    Pj                     @   s\  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 d dlmZ d dlmZ edgdddid	d
d Zedgddie dkrHd ndddd Zedgddidddd Zedgddedddddd Zdd Zedgdddid	d d! Zed"gd#dddid$d%d& Zd'd( Zd)d* Zd+d, Zed-gd.gdddid/d0d1 ZdS )2    )BytesION)image_comparison)FuncFormatterbbox_inches_tightTbbox_inchestight)remove_textsavefig_kwargc               	   C   s  g dg dg dg dg dg} dgd  }}t | }tt |d }g }d	}tt |}td
d
\}}	t|D ]}
|	j|| |
 ||ddd || |
  }|dg q<t	g  t
dd tjdgd dd |jdgd ddd |  tj|||dd d S )N)iR iب i{% it i}  )iv  i i0 i ir )i/\ i: iS i= i5	 )iO2 i? iL i i )ia  i i|< iD i-      g333333?g?   edgeb)bottomaligncolorr   )g333333?皙?)loc)r   r   z
lower leftbbox_to_anchorr   r   )cellText	rowLabels	colLabelsr   )lennparangezerospltsubplotsrangebarappendxticksxlimlegendreversetable)data
col_labels
row_labelsrowsind	cell_textwidthyofffigaxrow r2   U/home/thesage/.local/lib/python3.10/site-packages/matplotlib/tests/test_bbox_tight.pytest_bbox_inches_tight   s2   


r4    bbox_inches_tight_suptile_legendx86_64g{Gz?)r	   tolc                  C   s`   t jtddd t jddd t d t d d	d
 } t  j	t
|  t d d S )N
   za straight line)label)g?r   z
upper leftr   z
Axis titlezFigure titlec                 S   s   t | dkrdS t| S )N   zThe number 4)intstr)yposr2   r2   r3   y_formatter8   s   z:test_bbox_inches_tight_suptile_legend.<locals>.y_formatterzX axis)r   plotr   r   r$   titlesuptitlegcayaxisset_major_formatterr   xlabel)r?   r2   r2   r3   %test_bbox_inches_tight_suptile_legend.   s   

rG   z)bbox_inches_tight_suptile_non_default.png皙?c                  C   s    t  \} }| jdddd d S )NBooo      ?g?)xr=   )r   r   rB   r/   r0   r2   r2   r3   +test_bbox_inches_tight_suptitle_non_defaultB   s   rM   zbbox_inches_tight_layout.pngmpl20layoutr   
pad_inches)r   styler	   c                  C   s.   t jdd\} }|  jdd |d d S )Nconstrained)rO   rJ   )h_padequal)r   r   get_layout_engineset
set_aspectrL   r2   r2   r3   )test_bbox_inches_tight_layout_constrainedJ   s   rY   c                 C   s$   t  \}}|j| d ddd d S )Nzfoo.pngr   rO   rP   )r   r   savefig)tmp_pathr/   r0   r2   r2   r3   ,test_bbox_inches_tight_layout_notconstrainedS   s   r\   bbox_inches_tight_clippingc                  C   s   t tdtd t  } | dd | dd tjddgdd| j	ddd}t
jd }| jd	9  _|j|| jd
 t  j| d S )Nr8   r   r   id   bluerJ   )	transform	facecoloralphag      ?)r`   )r   scatterr   r   rC   set_xlimset_ylimmpatches	Rectangle	transDatampathPathunit_regular_stardeepcopyverticesset_clip_path	transAxesgcfartistsr!   )r0   patchpathr2   r2   r3   test_bbox_inches_tight_clippingZ   s   rt   bbox_inches_tight_rasterg333333?)r7   r   r	   c                  C   s"   t  \} }|jddgdd dS )z$Test rasterization with tight_layoutg      ?g       @T
rasterizedN)r   r   r@   rL   r2   r2   r3   test_bbox_inches_tight_rastero   s   rx   c                  C   s@   t  \} }|jddtdfd |  | jt ddd d S )Nr
   r   nan)xyr   png)r   format)r   r   annotatefloatset_axis_offrZ   r   rL   r2   r2   r3   test_only_on_non_finite_bboxw   s   r   c                  C   sn   t  \} }|tdd |jdd t }| j|dd |	d t 
|j\}}}||ks5J d S )Nr:   )   r   )r   rH   )ylimr   )r   r   )r   r   
pcolorfastr   r   reshaperW   r   rZ   seekimreadshape)r/   r0   bufheightr-   _r2   r2   r3   test_tight_pcolorfast   s   
r   c            	      C   s   ddl m}  d\}}d}tjd||| || fd}|d}|  |jd |jd t	
|| ||}|j|dd	 |jt d
ddd t }|j|d
dd |d t	| |}|d d d d df dk stJ |d d d d d df dk rJ |jdksJ d S )Nr   )Image)r8      r^   F)frameondpifigsize)r   r   r   r   Trv   r   pdf)r   rQ   r|   rP         )r   r8   r:   )PILr   r   figureadd_axesr   xaxisset_visiblerD   r   r   r   imshowrZ   r   r   asarrayopenallr   )	r   x_sizey_sizer   r/   r0   r'   outimr2   r2   r3   test_noop_tight_bbox   s$   

"&r   bbox_inches_fixed_aspectr{   )
extensionsr   r	   c                  C   sd   t ddi! t  \} }|ddg |dd |d W d    d S 1 s+w   Y  d S )Nzfigure.constrained_layout.useTr   r   rU   )r   
rc_contextr   r@   rd   rX   rL   r2   r2   r3   test_bbox_inches_fixed_aspect   s   "r   )ior   platformnumpyr   matplotlib.testing.decoratorsr   matplotlib.pyplotpyplotr   matplotlib.pathrs   ri   matplotlib.patchespatchesrf   matplotlib.tickerr   r4   machinerG   rM   dictrY   r\   rt   rx   r   r   r   r   r2   r2   r2   r3   <module>   sV    







