U
    \	a                     @   s   d dl m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did	dd Zedgdddidddd Zedgdddid	dd Zedgdddid	dd Zdd Zdd Zdd  ZdS )!    )BytesION)image_comparison)FuncFormatterZbbox_inches_tightTbbox_inchestight)remove_textsavefig_kwargc               	   C   s,  dddddgdddd	d
gdddddgdddddgdddddgg} dgd  }}t | }tt |d }g }d}tt |}tdd\}}	t|D ]6}
|	j|| |
 ||dd d! || |
  }|dg qt	g  t
d"d tjdgd d#d$ |jdgd d%d&d' |  tj|||d(d) d S )*NiR 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?   Zedgeb)bottomZaligncolorr   )g333333?皙?)loc)r   r   z
lower leftZbbox_to_anchorr   r   )ZcellTextZ	rowLabelsZ	colLabelsr   )lennparangezerospltsubplotsrangebarappendZxticksZxlimlegendreversetable)dataZ
col_labelsZ
row_labelsZrowsindZ	cell_textwidthZyofffigaxrow r$   D/tmp/pip-unpacked-wheel-wjyw_3jo/matplotlib/tests/test_bbox_tight.pytest_bbox_inches_tight   s2    

r&   Z bbox_inches_tight_suptile_legendFc                  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 d S )N   zThe number 4)intstr)yposr$   r$   r%   y_formatter6   s    z:test_bbox_inches_tight_suptile_legend.<locals>.y_formatterzX axis)r   plotr   r   r   titlesuptitlegcayaxisZset_major_formatterr   Zxlabel)r.   r$   r$   r%   %test_bbox_inches_tight_suptile_legend-   s    

r4   z)bbox_inches_tight_suptile_non_default.png皙?)r   r   Ztolc                  C   s    t  \} }| jdddd d S )NZBooo      ?g?)xr,   )r   r   r1   r!   r"   r$   r$   r%   +test_bbox_inches_tight_suptitle_non_default@   s    r9   Zbbox_inches_tight_clippingc                  C   s   t tdtd t  } | ddg | ddg tjddgdd| j	ddd}t
jd }| jd	9  _|j|| jd
 t  j| d S )Nr'   r   r
   id   Zbluer6   )	transformZ	facecoloralphag      ?)r;   )r   Zscatterr   r   r2   Zset_xlimZset_ylimmpatchesZ	RectangleZ	transDatampathPathZunit_regular_stardeepcopyZverticesZset_clip_pathZ	transAxesZgcfZartistsr   )r"   patchpathr$   r$   r%   test_bbox_inches_tight_clippingH   s     rC   Zbbox_inches_tight_rasterc                  C   s"   t  \} }|jddgdd dS )z$Test rasterization with tight_layout      ?g       @TZ
rasterizedN)r   r   r/   r8   r$   r$   r%   test_bbox_inches_tight_raster]   s    rF   c                  C   s@   t  \} }|jddtdfd |  | jt ddd d S )Nr	   r   nan)Zxyr   Zpng)r   format)r   r   Zannotatefloatset_axis_offsavefigr   r8   r$   r$   r%   test_only_on_non_finite_bboxe   s    rL   c                  C   sn   t  \} }|tdd |jdd t }| j|dd |	d t 
|j\}}}||ksjtd S )Nr)   )   rM   )r   r5   )Zylimr   )r   r   )r   r   Z
pcolorfastr   r   reshapesetr   rK   seekZimreadshapeAssertionError)r!   r"   bufheightr    _r$   r$   r%   test_tight_pcolorfastm   s    
rV   c            	      C   s8  ddl m}  d\}}d}tjd||| || fd}t|ddddg}|| |  |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 st|d d d d d df dk r$t|jdks4td S )Nr   )Image)r'      r:   F)ZframeondpiZfigsizeg        rD   TrE   r   Zpdf)r   
pad_inchesrH   )r   rZ         )rX   r'   r)   )ZPILrW   r   figureZAxesZadd_axesrJ   ZxaxisZset_visibler3   r   r   rN   ZimshowrK   r   rP   ZasarrayopenallrR   rQ   )	rW   Zx_sizeZy_sizerY   r!   r"   r   outZimr$   r$   r%   test_noop_tight_bboxz   s&    

"(ra   )ior   Znumpyr   Zmatplotlib.testing.decoratorsr   Zmatplotlib.pyplotZpyplotr   Zmatplotlib.pathrB   r>   Zmatplotlib.patchesZpatchesr=   Zmatplotlib.tickerr   r&   r4   r9   rC   rF   rL   rV   ra   r$   r$   r$   r%   <module>   sD   
 
 
 
 
