B
    Mô`6  ã               @   sš  d dl Z d dlZd dlZd dlZd dlmZ d dlZd dl	m
Z
 d dlmZmZ d dlmZ d dlZdd„ Zdd	„ Zej d
e d¡e d¡e d¡fdfe d¡e d¡e d¡fdfe d¡e d¡e d¡fdfe d¡e d¡e d¡fdfe d¡e d¡e d¡fdfe d¡e d¡e d¡fdfe d¡e d¡e d¡fdfe d¡e d¡e d¡fdfd ggfdfd gd gd ggfdfg
¡dd„ ƒZdd„ Zdd„ Zd d!„ Zd"d#„ Ze
d$gd%d&id'd(d)�d*d+„ ƒZe
d,gd'd(d-�d.d/„ ƒZe
d0gd'd1�d2d3„ ƒZe
d4gd5d(d-�d6d7„ ƒZe
d8gd'd(e  ¡ d9k�r:d nd:d;�d<d=„ ƒZ!e
d>d?gd'd1�d@dA„ ƒZ"dBdC„ Z#dDdE„ Z$ej dFdGe%dHfdIe&dJfd ggd ggg gdd'd fe&dKfd ggd ggd ggdd'd fe&dLfe dM¡ 'dN¡gdO d ggd'd f˜e&dPfg¡dQdR„ ƒZ(dSdT„ Z)dUdV„ Z*ej dWdXdYdZd[g¡d\d]„ ƒZ+e
d^gd'd(d-�d_d`„ ƒZ,e
dagd'd(dbd;�dcdd„ ƒZ-e
degdfgd'd(dg�dhdi„ ƒZ.ej djdkdldmg¡dndo„ ƒZ/dS )pé    N)Úassert_array_almost_equal)Úimage_comparison)ÚpyplotÚ
rc_context)ÚLogNormc              C   s>   t  d¡} t  d¡}t j d¡}t ¡ \}}| | ||¡ d S )Né
   é	   )r   r   )ÚnpÚarangeÚrandomÚpltÚsubplotsÚcontour)ÚxÚyÚzÚfigÚax© r   úA/tmp/pip-unpacked-wheel-0c1wfn4v/matplotlib/tests/test_contour.pyÚtest_contour_shape_1d_valid   s
    

r   c              C   sN   t  d¡} t  d¡}t  | |¡\}}t j d¡}t ¡ \}}| |||¡ d S )Nr   r   )r   r   )r	   r
   Úmeshgridr   r   r   r   )r   r   ZxgZygr   r   r   r   r   r   Útest_contour_shape_2d_valid   s    

r   zargs, messager   )r   r   z6Length of x (9) must match number of columns in z (10)r   z3Length of y (10) must match number of rows in z (9))r   r   z4Number of dimensions of x (2) and y (1) do not matchz4Number of dimensions of x (1) and y (2) do not match)r   r   z-Shapes of x (9, 9) and z (9, 10) do not matchz-Shapes of y (9, 9) and z (9, 10) do not match)é   r   r   z'Inputs x and y must be 1D or 2D, not 3DzInput z must be 2D, not 3DzDInput z must be at least a (2, 2) shaped array, but has shape (1, 1)c          	   C   s:   t  ¡ \}}tjtt |¡d�� |j| Ž  W d Q R X d S )N)Úmatch)r   r   ÚpytestÚraisesÚ	TypeErrorÚreÚescaper   )ÚargsÚmessager   r   r   r   r   Útest_contour_shape_error#   s    r"   c           	   C   s^   t  d¡} t j d¡}t ¡ \}}t t¡�}|j| | |g d� W d Q R X t	|ƒdksZt
‚d S )Nr   )r   r   )Úlevelsé   )r	   r
   r   r   r   r   ÚwarnsÚUserWarningr   ÚlenÚAssertionError)r   r   r   r   Úrecordr   r   r   Útest_contour_empty_levels?   s    
r*   c              C   s`   t  d¡ d¡} t ¡ \}}| | d¡}t|jƒdks:t‚|j| dd�}|j|jk 	¡ s\t‚d S )Né   )r   é   é   r$   )r#   )
r	   r
   Úreshaper   r   r   r'   r#   r(   Úall)r   r   r   Zcs1Zcs2r   r   r   Útest_contour_NlevelsJ   s    r0   c           	   C   st   t  d¡} t  d¡}t ¡ \}}ddi}t t¡�(}|j| | |dgd�}|j	||d� W d Q R X t
|ƒdkspt‚d S )Nr   )r   r   g      ð?z%1.2f)r#   )Úfmtr$   )r	   r
   Úzerosr   r   r   r%   r&   r   Úclabelr'   r(   )r   r   r   r   r1   r)   Úcsr   r   r   Útest_contour_badlevel_fmtU   s    

r5   c           	   C   sX   t  d¡} t  d¡}t ¡ \}}t t¡�}| | | |¡ W d Q R X t	|ƒdksTt
‚d S )Nr   )r   r   r$   )r	   r
   Zonesr   r   r   r%   r&   r   r'   r(   )r   r   r   r   r)   r   r   r   Útest_contour_uniform_ze   s    

r6   Zcontour_manual_labelsÚdpiéÈ   TZmpl20)Zsavefig_kwargÚremove_textÚstylec              C   s|   t  t  dd¡t  dd¡¡\} }t  t  t| ƒt|ƒg¡d¡}tjddd� t | ||¡}t  	ddd	g¡}tj
||d
� d S )Nr   r   é   )é   r;   r8   )Úfigsizer7   )g      ø?g      @)g      ø?gš™™™™™@)g      ø?g      @)Úmanual)r	   r   r
   ÚmaxÚdstackÚabsr   Úfigurer   Úarrayr3   )r   r   r   r4   Úptsr   r   r   Útest_contour_manual_labelsp   s     rE   zcontour_labels_size_color.png)r9   r:   c              C   s~   t  t  dd¡t  dd¡¡\} }t  t  t| ƒt|ƒg¡d¡}tjdd� t | ||¡}t  	dddg¡}tj
||d	d
d� d S )Nr   r   r;   )r<   r;   )r=   )g      ø?g      @)g      ø?gš™™™™™@)g      ø?g      @Úsmall)ÚrÚg)r>   ZfontsizeÚcolors)r	   r   r
   r?   r@   rA   r   rB   r   rC   r3   )r   r   r   r4   rD   r   r   r   Útest_contour_labels_size_color}   s     rJ   z$contour_manual_colors_and_levels.png)r9   c              C   sà   t  dd¡\} }t d¡ dd¡}ddddd	g}ddd
dg}xžt|jƒD ]�\}}|d dk}ddddg|d  }|r°|dkr€dnd }	|dkr�dnd }
|j|||	|
… ||d�}n|j||d d… ||d�}t j	||d� qHW d S )Nr;   r,   r+   r   ZredZyellowZpinkZblueZblacké   r   g        ÚneitherÚminr?   Úboth)r?   rL   r$   )rM   rL   éÿÿÿÿ)rI   r#   Úextend)r   )
r   r   r	   r
   r.   Ú	enumerateZflatÚcontourfr   Úcolorbar)Ú_ÚaxsÚdatarI   r#   Úir   ZfilledrP   Zfirst_colorZ
last_colorÚcr   r   r   Ú$test_given_colors_levels_and_extendsŠ   s    
rY   zcontour_datetime_axis.pngFc                 sD  t  ¡ } | jdddd� t ddd¡‰ t ‡ fdd„td	ƒD ƒ¡}t d	¡}t t d	¡t d	¡¡\}}|| }t  	d
¡ t  
|||¡ t  	d¡ t  |||¡ tj|tj d	dd�}tj|d d …tjf d	dd�}t  	d¡ t  
|||¡ t  	d¡ t  |||¡ x:|  ¡ D ].}x&| ¡ D ]}| d¡ | d¡ �qW �qW d S )Ngš™™™™™Ù?g\�Âõ(\ï?g333333Ã?)ZhspaceÚtopZbottomiÝ  r$   c                s   g | ]}ˆ t j|d � ‘qS ))Údays)ÚdatetimeÚ	timedelta)Ú.0Úd)Úbaser   r   ú
<listcomp>¬   s    z.test_contour_datetime_axis.<locals>.<listcomp>é   éÝ   éÞ   r   )Zaxiséß   éà   Úrighté   )r   rB   Úsubplots_adjustr\   r	   rC   Úranger
   r   Zsubplotr   rR   ÚrepeatZnewaxisZget_axesZget_xticklabelsZset_haZset_rotation)r   r   r   Zz1Zz2r   r   Úlabelr   )r`   r   Útest_contour_datetime_axis¦   s*    





rm   z!contour_test_label_transforms.pngÚx86_64g{®Gáz´?)r9   r:   Ztolc              C   s(  d} t  dd| ¡}t  dd| ¡}t  ||¡\}}t  |d |d   d ¡dt j  }t  |d d d |d d	 d   d ¡dt j d	 d  }d
||  }t dd¡\}}	|	 |||¡}
dddg}dddg}|
 ¡  x"|D ]\}}|
j	||dd d� qàW x$|D ]\}}|
j	||ddd� �qW d S )Ngš™™™™™™?g      Àg      @g       Àg       @r;   r$   g      ø?g      à?g      $@)éØ   é±   )ig  i"  )i	  i–  )éþÿÿÿg      à?)r   g      ø¿)gffffff@r$   T)ÚinlineZ	transformF)
r	   r
   r   ÚexpÚpir   r   r   r3   Zadd_label_near)Údeltar   r   ÚXÚYZZ1ZZ2ÚZr   r   ÚCSZ
disp_unitsZ
data_unitsr   r   r   Útest_labelsÀ   s"    &*

rz   zcontour_corner_mask_False.pngzcontour_corner_mask_True.pngc              C   s¶   d} d}d}t j dg¡ t  t  dd| ¡t  dd| ¡¡\}}t  d| ¡t  d| ¡ |t j | | ¡  }t j | | ¡|k}t jj	||d	�}x"d
D ]}t
 ¡  t
j||d� q”W d S )Né<   gffffffî?g      ð?r$   r   g       @é   rK   )Úmask)FT)Úcorner_mask)r	   r   Úseedr   ÚlinspaceÚcosÚsinÚrandÚmarC   r   rB   rR   )ÚnZ
mask_levelZ	noise_ampr   r   r   r}   r~   r   r   r   Útest_corner_maskß   s    $.
r†   c           	   C   sB   ddgddgg} t  ¡  t t¡� t  | ddg¡ W d Q R X d S )Ngš™™™™™¹?g333333Ó?g      à?gffffffæ?g      ð?g        )r   rB   r   r   Ú
ValueErrorrR   )r   r   r   r   Útest_contourf_decreasing_levelsñ   s    rˆ   c              C   sF   t  d¡ d¡} tjddd�}tj| |d�}t|jt  ddd¡ƒ d S )	Nr+   )r   r,   r,   T)ZnbinsZ	symmetric)Úlocatoriôÿÿÿr-   )	r	   r
   r.   r   ZMaxNLocatorrR   r   r#   r€   )r   r‰   r4   r   r   r   Útest_contourf_symmetric_locatorù   s    rŠ   zargs, cls, messager   z,function takes exactly 6 arguments (0 given))r$   r;   r   r,   r-   r<   z#Expected 2-dimensional array, got 0z9x, y and z must all be 2D arrays with the same dimensionsz*x, y and z must all be at least 2x2 arraysr,   )r;   r;   r   zCIf mask is set it must be a 2D array with the same dimensions as x.c          	   C   s<   ddl m} tj|t |¡d�� tjj| Ž  W d Q R X d S )Nr   )Ú_contour)r   )Ú
matplotlibr‹   r   r   r   r   ÚmplÚQuadContourGenerator)r    Úclsr!   r‹   r   r   r   Útest_internal_cpp_api  s    r�   c           	   C   s\   ddl m}  ddgddgg}tj |||d dd¡}tjtdd�� | dd¡ W d Q R X d S )	Nr   )r‹   r$   r;   r   Tz(filled contour levels must be increasing)r   )rŒ   r‹   r�   rŽ   r   r   r‡   Zcreate_filled_contour)r‹   ZarrZqcgr   r   r   Útest_internal_cpp_api_2  s    r‘   c              C   sT   t  t  ddd¡t  ddd¡¡\} }t  | |¡}t ¡  t | ||¡}t |¡ d S )Nrq   r;   r,   )r	   r   r€   Úhypotr   rB   r   r3   )r   r   rG   r4   r   r   r   Útest_circular_contour_warning  s
    $r“   z-use_clabeltext, contour_zorder, clabel_zorder)Té{   iÒ  )Fr”   iÒ  )Tr”   N)Fr”   Nc             C   sè   t  t  dd¡t  dd¡¡\}}t  t  t|ƒt|ƒg¡d¡}tjdd�\}\}}|j||||d�}	|j	||||d�}
|	j
|| d�}|
j
|| d�}|d kr¤d| }n|}x|D ]}| ¡ |ks®t‚q®W x|D ]}| ¡ |ksÌt‚qÌW d S )Nr   r   r;   )Zncols)Úzorder)r•   Úuse_clabeltext)r	   r   r
   r?   r@   rA   r   r   r   rR   r3   Z
get_zorderr(   )r–   Zcontour_zorderZclabel_zorderr   r   r   r   Úax1Úax2r4   Z	cs_filledZclabels1Zclabels2Zexpected_clabel_zorderr3   r   r   r   Útest_clabel_zorder%  s     


r™   zcontour_log_extension.pngc              C   s>  t jdd�} | jddd� |  d¡}|  d¡}|  d¡}t d	d
d¡}t d|¡ dd¡}t dd¡}t d|¡}|j	|t
| ¡ | ¡ d�d�}|j	||t
| ¡ | ¡ d�dd�}	|j	||t
| ¡ | ¡ d�dd�}
t j||d�}|j ¡ dksôt‚t j|	|d�}|j ¡ dk�st‚t j|
|d�}t|j ¡ ddgdƒ d S )N)r   r-   )r=   gš™™™™™©?gffffffî?)Úleftrg   éƒ   é„   é…   g      Àg      #@i°  r   rh   é(   g      Àg      @g      $@)ZvminZvmax)ÚnormrL   )r#   rŸ   rP   rN   )r   )g:Œ0âŽyE>g    _ B)g-Cëâ6?g    €„.Ag¼á›TV” ?gÇe€ÔR HAr;   )r   rB   ri   Zadd_subplotr	   r€   Úpowerr.   r
   rR   r   rM   r?   rS   r   Úget_ylimr(   r   )r   r—   r˜   Zax3Zdata_exprV   Z
levels_expr#   Zc1Úc2Úc3Úcbr   r   r   Útest_contourf_log_extension>  s0    


r¥   zcontour_addlines.pngg¸…ëQ¸ž?c              C   sp   t  ¡ \} }tj d¡ tj dd¡d }| |¡}| |d ¡}|  |¡}| 	|¡ t
|j ¡ ddgdƒ d S )Ni,N,r   i'  iè  gdÌ]KÈ“\@g6«>W'zÃ@r   )r   r   r	   r   r   rƒ   Z
pcolormeshr   rS   Z	add_linesr   r   r¡   )r   r   rv   ZpcmZcontr¤   r   r   r   Útest_contour_addlinesc  s    


r¦   Zcontour_unevenZpng)Zbaseline_imagesÚ
extensionsr9   r:   c              C   s†   t  d¡ dd¡} t dd¡\}}|d }|j| dddddgd	�}|j||d
d� |d }|j| dddddgd	�}|j||dd� d S )Né   r,   r<   r$   r;   r   r   rb   )r#   Zproportional)r   ÚspacingÚuniform)r	   r
   r.   r   r   rR   rS   )r   r   rU   r   r4   r   r   r   Útest_contour_unevens  s    r«   zCrc_lines_linewidth, rc_contour_linewidth, call_linewidths, expected)g®Gáz®ó?NNg®Gáz®ó?)g®Gáz®ó?gö(\�Âõ@Ngö(\�Âõ@)g®Gáz®ó?gö(\�Âõ@g®Gáz@g®Gáz@c          	   C   sb   t | |dœd��H t ¡ \}}t d¡ dd¡}|j||d�}|jd d |ksTt‚W d Q R X d S )N)zlines.linewidthzcontour.linewidth)Úrcr+   r,   r   )Z
linewidthsr   )	r   r   r   r	   r
   r.   r   Ztlinewidthsr(   )Zrc_lines_linewidthZrc_contour_linewidthZcall_linewidthsÚexpectedr   r   rv   r4   r   r   r   Útest_contour_linewidth€  s    	r®   )0r\   Úplatformr   Znumpyr	   Znumpy.testingr   rŒ   r�   Zmatplotlib.testing.decoratorsr   r   r   r   Zmatplotlib.colorsr   r   r   r   ÚmarkZparametrizer
   Úemptyr"   r*   r0   r5   r6   rE   rJ   rY   rm   Úmachinerz   r†   rˆ   rŠ   r   r‡   r.   r�   r‘   r“   r™   r¥   r¦   r«   r®   r   r   r   r   Ú<module>   sœ   
"$		$