o
    g&)                     @   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 dHd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% Ze	d&gd'd( Zd)d* ZdId.d/Ze	d0d1gd2d3 Zd4d5 Zej !d6d7d8gd9d: Z"d;d< Z#d=d> Z$d?d@ Z%dAdB Z&dCdD Z'ej (dEdFdG Z)dS )J    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   _/home/ubuntu/cloudmapper/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.1g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   r7   rowspan)r   r	   )r9   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   rF   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   )rI   r   r   r   g?)rK   h_padNrI   )warningscatch_warningssimplefilterUserWarningr   figuremplgridspecGridSpecadd_subplotr   r!   r   r   mintopmaxbottom)	r#   gs1r)   r*   gs2ssr   rX   rZ   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   rc   tight_layout8c                  C   s.   t  } | ddi |  }t|dd dS )#Test automatic use of tight_layout.pad皙?r   r   N)r   rR   set_tight_layoutrV   r   r"   r   r   r   test_tight_layout8   s   ri   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   rn   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 )re   r/   out   r
   )tickdirlengthwidth    Tminor)rq   rr   rs   tick1Onwhichr   )ru      inr0   inout   gK?gCl?gʡE?gB`"?gI+?g/$?gQ?gm?N)r   rR   rV   xaxisset_tick_paramsyaxis	set_ticksr!   	enumerateaxesr   rA   roundget_position
get_points)r#   r   ansnnr   r   r   test_outward_ticks   s@   





r   r>   rg   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   rI   r6   Noner   F)rs   height	facecolor	edgecolor	linewidthantialiasedcenterg        )ra   childrf   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   rk   )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)      r6   )r   r   )r   r
   r
   r   r8   )r   r:   pytestwarnsrQ   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   rJ   )r   r    set_xlimset_ylimannotater   r   r   rQ   r!   rs   )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_suptitle7  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   rS   backendsbackend_pdfRendererPdf)selfargskwargsunpatched_initr   r   __init__C  s   z'test_non_agg_renderer.<locals>.__init__r   )rS   backend_basesRendererBaser   setattrr   r    r!   )monkeypatchrecwarnr   r#   r   r   r   r   test_non_agg_renderer?  s
   
r   )r   )r>   rg   r   )*rN   numpyrA   numpy.testingr   r   
matplotlibrS   matplotlib.testing.decoratorsr   matplotlib.pyplotpyplotr   matplotlib.offsetboxr   r   matplotlib.patchesr   r   r$   r-   r3   r;   rF   r^   rc   ri   rn   r   r   r   r   markparametrizer   r   r   r   r   r   backendr   r   r   r   r   <module>   sX    







)



!

'
	
