o
    Ďi6                     @   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 ejdgZdPd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e	dgdddd  Ze	d!gdd"d#d$d% Ze	d&gddd'd( Zd)d* ZdQd.d/Z d0d1 Z!d2d3 Z"ej#d4d5d6gd7d8 Z$d9d: Z%d;d< Z&d=d> Z'd?d@ Z(dAdB Z)ej*dCdDdE Z+dFdG Z,dHdI Z-dJdK Z.dLdM Z/dNdO Z0dS )R    N)assert_array_equal)image_comparison)AnchoredOffsetboxDrawingArea)	Rectangletext_placeholders   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   ]/home/jeff/fluffinator/venv/lib/python3.10/site-packages/matplotlib/tests/test_tightlayout.pyexample_plot   s
   r   tight_layout1mpl20)stylec                  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   


r5   tight_layout4c                  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_layout4:   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!   r4   nparangereshapeimshowr#   )r   arrr   r   r   test_tight_layout5H   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_layout6Q   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_layout7{   s   re   tight_layout8{Gzt?)r   tolc                  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
   rp   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   ru   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 )ri   r1   out   r   )tickdirlengthwidth    Tminor)rx   ry   rz   tick1Onwhichr   )r|      inr2   inout   gZd;O?g\(\?gʡE?gB`"?gd;O?g/$?gDl?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@   rk   blackc              
   C   s   |d| }}| | f| df| |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)dS )z&
    Surround ax with OffsetBoxes
    r	   rK   r7   Noner   F)rz   height	facecolor	edgecolor	linewidthantialiasedcenterg        )rc   childrm   frameonbbox_to_anchorbbox_transform	borderpadN)r   r   
add_artistr   	transAxes)r   sizemargincolormmpanchor_pointspointda
backgroundanchored_boxr   r   r   add_offsetboxes   s4   

r   c                     s  d g d ddg  fdd} | d\}}|   | d\}}|   t|j|jD ],\}}| }| }|j|jksGJ |j|jk sOJ |j|jksWJ |j|jk s_J q3g }	|jD ]$}| D ]}
t	|
t
ssqk|
 }|	D ]	}||rJ qy|	| qkqe| d\}}|jD ]}| D ]}
t	|
t
r|
d qq|   t|j|jD ]\}}| }| }t| |  qd S )	Nr
   )redbluegreenyellowr   r	   c                    sP   t \}}t|j D ]\}}|j|d | r#t|d|d q||fS )N)r      )r!   r"   zipflatr   r   )
with_boxesr%   axsr   r   colorscolsrowsxyr   r   	_subplots   s   z0test_tight_layout_offsetboxes.<locals>._subplotsFT)r#   r   r   r   x0x1y0y1get_children
isinstancer   get_window_extentoverlapsappendrr   r   r   )r   fig0axs0fig1axs1ax0r+   bbox0bbox1bboxesr   bbox
other_bboxfig2axs2r   r,   bbox2r   r   r   test_tight_layout_offsetboxes   sL   	

	


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_horizontal1     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_vertical8  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#   rz   )r%   r   p1p2r   r   r   test_collapsedH  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drawr   r   r   )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__i  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_renderere  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   gQ?)caxzThis figure includes Axesmatch)r!   r"   scatterr   add_axesr   r   r   colorbarr   r   rS   r#   )r%   r   ptsax_rectr  r   r   r   test_manual_colorbart  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  rm   333333?)r!   r"   r   r   PendingDeprecationWarningset_tight_layoutro   r$   r   r   r   test_tight_pads  s   r)  c                  C   s    t jddid\} }|   d S )Nrm   r&  r   )r!   r"   ro   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@   rk   r   )1rP   numpyrC   numpy.testingr   r   
matplotlibrU   matplotlib.testing.decoratorsr   matplotlib.pyplotpyplotr!   matplotlib.offsetboxr   r   matplotlib.patchesr   markusefixtures
pytestmarkr   r&   r/   r5   r<   rH   r`   re   rp   ru   r   r   r   r   parametrizer   r   r   r   r   r   backendr
  r  r%  r)  r*  r,  r   r   r   r   <module>   s`    








)

	

#H
	

