U
    mdHd                     @   sx  d dl Z d dlZd dlZd dlZd dlZd dlmZmZ d dl	Z
d dlmZ d dl	mZmZmZ d dlmZ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ed gd!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"d0d1d2 Z!ed3gd!d"e" d4kr6d nd5d6d7d8 Z#ed9d:gd!d'd;d< Z$d=d> Z%d?d@ Z&dAdB Z'ejdCdDdEdFdGgdHdI Z(edJgd!d"dKd6dLdM Z)edNgd!d"e" dOkrdPndQd6dRdS Z*edTgdUgd!d"dVdWdX Z+ejdYdZd[d\gd]d^ Z,ej-d_d`da Z.edbgdUgd!dcddde Z/dfdg Z0edhgdUgd!dcdidj Z1edkgdUgd!dcdldm Z2dndo Z3dpdq Z4e
j56drdsdt Z7dudv Z8dwdx Z9ejdydzej:fd{ej;fd|ej<fd}ej=fd~gdd Z>ejddzd{d|d}gdd Z?edgdUgd!dcdd Z@dd ZAejdddddgdd ZBejdddddgdd ZCdd ZDdd ZEdS )    N)assert_array_almost_equalassert_array_almost_equal_nulp)image_comparison)pyplot
rc_contextticker)LogNorm
same_colorc                  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   V/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/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 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   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 5 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   sf   t  \} }|jtjddg d |jtdddgd}|j|ddid |t	d d S )Nr   levelsQ   r   d   z%1.2f)fmt)
r   r   r   r   r   randr   reshapeclabelZones)r   r   csr   r   r   test_contour_no_valid_levelsA   s
    r3   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   r0   r   r   r   lenr+   AssertionErrorall)r   r   r   Zcs1Zcs2r   r   r   test_contour_NlevelsM   s    r<   Zcontour_manual_labelsTZmpl20)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
 t 	dddg}tj
||ddd d S )Nr   r      )   r?      )figsizeZdpi)      ?      @)rC   皙@)rC         @)manual)       @rD   )rH   rE   )rH   rF   Zsmall)rg)rG   fontsizecolors)r   r   r   maxdstackabsr   figurer   arrayr1   )r   r   r   r2   Zptsr   r   r   test_contour_manual_labelsX   s     rR   z$contour_manual_colors_and_levels.png)r=   c                  C   s   dt jd< t dd\} }tddd}ddd	d
dg}ddddg}t|jD ]\}}|d dk}ddddg|d  }|r|dkrdnd }	|dkrdnd }
|j|||	|
 ||d}n|j	||d d ||d}t j
||d qPd S )NFpcolormesh.snapr?   r6   r4   r   redyellowZpinkblueblack   r           neitherminrM   both)rM   rZ   r8   )r[   rZ   )rL   r+   extendr   )r   rcParamsr   r   r   r0   	enumerateZflatcontourfr   colorbar)_axsdatarL   r+   ir   filledr^   Zfirst_colorZ
last_colorcr   r   r   $test_given_colors_levels_and_extendse   s(    
  rj   zcontour_log_locator.svgF)r>   r=   c               	   C   s   t  \} }d}tdd|}tdd|}t||\}}t|d  |d  }t|d d  |d d  }|d|  }	|j|	t d	}
t	|
j
td
tdd | j|
|d}t	|j |
j
 d S )Nr-         rD          rH   r?   r   2   locator      $@ir   r_   )r   r   r   linspacer   exprb   r   Z
LogLocatorr   r+   powerr   rc   r   Z
get_yticks)r   r   Nr   r   XYZ1Z2rf   ri   cbr   r   r   test_log_locator_levels   s     rz   zcontour_datetime_axis.png)r>   c                     s<  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 ||| |  D ]*}| D ]}|d |d qqd S )Ng?g\(\?333333?)Zhspacetopbottomi  r8   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   rP   subplots_adjustr   r   rQ   ranger   r   Zsubplotr   rb   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*    





r   z!contour_test_label_transforms.pngx86_64g{Gz?)r=   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}|
  |D ]\}}|
j	||dd d q|D ]\}}|
j	||ddd qd S )N皙?rk   rD   rl   rH   r?   r8   g      ?      ?rp   )      )ig  i"  )i	  i  )r   )r   g      )gffffff@r8   T)inlineZ	transformF)
r   r   r   rr   pir   r   r   r1   Zadd_label_near)deltar   r   ru   rv   rw   rx   Zr   r   CSZ
disp_unitsZ
data_unitsr   r   r   test_labels   s$    &*

r   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	}d
D ]}t
  t
j||d qd S )N<   ffffff?rC   r8   r   rH      rX   mask)FTcorner_mask)r   r   seedr   rq   cossinr/   marQ   r   rP   rb   )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 5 Q R X d S )Ng?g333333?r   ffffff?rC   rY   )r   rP   r"   r#   
ValueErrorrb   )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 )	Nr4   r5   r6   T)ZnbinsZ	symmetricrn   ir7   )	r   r   r0   r   ZMaxNLocatorrb   r   r+   rq   )r   ro   r2   r   r   r   test_contourf_symmetric_locator   s    r   c                  C   sT   t t dddt ddd\} }t | |}t  t| ||}t| d S )Nr   r?   r6   )r   r   rq   hypotr   rP   r   r1   )r   r   rI   r2   r   r   r   test_circular_contour_warning   s
    $r   z-use_clabeltext, contour_zorder, clabel_zorder)T{     )Fr   r   )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rd| }n|}|D ]}| |kstq|D ]}| |kstqd S )Nr   r   r?   )ncols)zorder)r   use_clabeltext)r   r   r   rM   rN   rO   r   r   r   rb   r1   Z
get_zorderr:   )r   Zcontour_zorderZclabel_zorderr   r   r   r   ax1ax2r2   Z	cs_filledZclabels1Zclabels2Zexpected_clabel_zorderr1   r   r   r   test_clabel_zorder   s      
r   zcontour_log_extension.pnggv?c                  C   s$  dt jd< t jdddd\} \}}}| j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stt j|	|d}t|j td t j|
|d}d S )NFrS   r8   r   )r   r7   rB   g?r   )leftr   g      g      #@i  r   r   (   g      g      @rp   )ZvminZvmax)normrZ   )r+   r   r^   r\   r_   )g:0yE>g    _B)-C6?g    .A)r   r`   r   r   r   rq   rs   r0   r   rb   r   r[   rM   rc   r   get_ylimr:   r   rQ   )r   r   r   ax3Zdata_exprf   Z
levels_expr+   c1c2c3ry   r   r   r   test_contourf_log_extension  s.    
r   zcontour_addlines.png)aarch64ppc64les390xr{   gQ?c                  C   sz   dt jd< t  \} }tjd tjddd }||}||d }| 	|}|
| t|j ddgd	 d S )
NFrS   i,N,r   i'  i  gd]Kȓ\@g6>W'z@r   )r   r`   r   r   r   r   r/   Z
pcolormeshr   rc   	add_linesr   r   r   )r   r   ru   Zpcmcontry   r   r   r   test_contour_addlines=  s    



r   Zcontour_unevenZpng)baseline_images
extensionsr=   r>   c                  C   s   dt jd< 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 )NFrS      r6   r@   r8   r?   r   r   r   r*   Zproportional)r   spacinguniform)r   r`   r   r   r0   r   rb   rc   )r   r   re   r   r2   r   r   r   test_contour_unevenR  s    
r   zCrc_lines_linewidth, rc_contour_linewidth, call_linewidths, expected)Gz?NNr   )r   (\@Nr   )r   r   Gz@r   c              	   C   sb   t | |ddH t \}}tddd}|j||d}|jd d |ksTtW 5 Q R X d S )N)zlines.linewidthzcontour.linewidth)rcr4   r6   r   )
linewidthsr   )	r   r   r   r   r   r0   r   Ztlinewidthsr:   )Zrc_lines_linewidthZrc_contour_linewidthZcall_linewidthsexpectedr   r   ru   r2   r   r   r   test_contour_linewidthb  s    	r   Zpdfc                   C   s    t t ddgddgg d S )Nr8   r?   r   r6   )r   r1   r   r   r   r   r   test_label_nonaggs  s    r   Zcontour_closed_line_loop)r   r   r=   c                  C   sf   dddgdddgdddgdddgg} t jdd\}}|j| dgdgdd	 |d
d |d
d d S )Nr   r?   r8   )r?   r?   r   r   r   r   )r   alphagg @g@)r   r   r   Zset_xlimZset_ylim)r   r   r   r   r   r   test_contour_closed_line_loopy  s
    $r   c                  C   sx   t ddgddg\} }| | }t \}}|| ||}|| ||}|j|jksXt|||}|j|jksttd S )NrY   rC   )r   r   r   r   rb   r   _contour_generatorr:   )r   r   r   r   r   Zqcs1Zqcs2Zqcs3r   r   r   test_quadcontourset_reuse  s    r   Zcontour_manualc            
      C   s  ddl m}  tjdd\}}d}ddgddgddggg}ddgddggddgdd	ggg}ddgdd	gddgddgddggg}ddgddgddgddgddggdd	gdd	gddggg}| |dddg||gd
|d | |ddg||gdddgd d	dgddgddgd	dgd	dgddgddgddgddgddgg
g}ddddddddddg
g}	| |ddg|g|	gd
|d | |dg|g|	gddd d S )Nr   )
ContourSetr6   r6   r   Zviridisr?   r8   r   r6   T)rh   cmaprI   k)r   rL   r   r7   r@   O   )rL   r   )Zmatplotlib.contourr   r   r   )
r   r   r   r   Zlines0Zlines1Zfilled01Zfilled12Zsegskindsr   r   r   test_contour_manual  s*     $     r   Z!contour_line_start_on_corner_edgec            	      C   s   t jdd\} }tdddddgdddg\}}d|d d  |d d  }tj|td	}d
 |d< |d< tjj||d}|j|||d
d}| 	|}|j
|||d
dd}|| d S )N)r@   r7   r   r   r8   r?   r   r6   g333333?ZdtypeT)r8   r8   )r8   r   r   r   r   )r   rL   )r   r   r   r   
zeros_likeboolr   rQ   rb   rc   r   r   )	r   r   r   r   r   r   rh   Zcbarlinesr   r   r   &test_contour_line_start_on_corner_edge  s     
r   c                  C   s   t d} t t j t | d d dd  }t|d}|jdddd	}d
}t|| |jdddd	}d}t|| |jdddd	}d}t|| |jddddd}d}t|| d S )N   r   r7   r?   r         9@r   r8   Fpixel)r8   r   !   YİØt?r   gb?rX   )r8   r   r7   g`3@gDlpf?gݓ?)r   r      gͰQo&?ghW!@g|o^}?r7   r   indicesr   )r7   r      gA*Ŏ@g      @gA?)	r   r   rr   r   sumr   r   find_nearest_contourr   )xyimgr2   Znearest_contourZexpected_nearestr   r   r   test_find_nearest_contour  s$    
&


r   c               	   C   s   t d} t t j t | d d dd  }t|d}tjt	dd |j
d	d	d
d W 5 Q R X tjt	dd |j
d	ddd
d W 5 Q R X tjt	dd |j
ddddd W 5 Q R X d S )Nr   r7   r?   r   r   r   z(Method does not support filled contours.r    r8   Fr   r   r   )r?   r   T)r   r   rr   r   r   r   rb   r"   r#   r   r   )r   r   r2   r   r   r   #test_find_nearest_contour_no_filled  s    
&r   defaultc                  C   s^   t   } t jtddddddddgd}| | d	d
 | jD dddhksZt	d S )Ngư>r   r-   r   gh㈵>gh㈵>gh㈵?r*   c                 S   s   h | ]}|  qS r   )Zget_text)r   textr   r   r   	<setcomp>  s     z<test_contour_autolabel_beyond_powerlimits.<locals>.<setcomp>z0.25z1.00z4.00)
r   rP   add_subplotr   r   Z	geomspacer0   r1   Ztextsr:   )r   r2   r   r   r   )test_contour_autolabel_beyond_powerlimits  s    
r   c                     s   ddl m  tdd} | dd}| | }tj|dddgdd	d
gdd}|jd |j	d |
  | \}}|ddddgkstd}t fdd|D sttdd t||D std S )Nr   	Rectangler8   r   r]   r   rm   #FFFF00#FF00FFz#00FFFFr\   r+   rL   r^   rT   rV   z$x \leq -1e+250s$z$10.0 < x \leq 30.0$z$30.0 < x \leq 50.0$z$x > 1e+250s$)rV   r  r  rT   c                 3   s   | ]}t | V  qd S N
isinstancer   ar   r   r   	<genexpr>  s     z0test_contourf_legend_elements.<locals>.<genexpr>c                 s   s    | ]\}}t | |V  qd S r  )r	   Zget_facecolorr   r  ri   r   r   r   r	    s   )Zmatplotlib.patchesr   r   r   r0   r   rb   r   Zset_overZ	set_underchangedlegend_elementsr:   r;   zip)r   r   hr2   artistslabelsZexpected_colorsr   r   r   test_contourf_legend_elements  s,    
r  c                     s   ddl m  tdd} | dd}| | }dddg}tj|dd	d
g|dd}| \}}|dddgksltt	 fdd|D stt	dd t
||D std S )Nr   LineCollectionr8   r   r]   rV   z#00FF00rT   r   rm   r\   r  z
$x = 10.0$z
$x = 30.0$z
$x = 50.0$c                 3   s   | ]}t | V  qd S r  r  r  r  r   r   r	    s     z/test_contour_legend_elements.<locals>.<genexpr>c                 s   s    | ]\}}t | |V  qd S r  )r	   	get_colorr
  r   r   r   r	    s   )Zmatplotlib.collectionsr  r   r   r0   r   r   r  r:   r;   r  )r   r   r  rL   r2   r  r  r   r  r   test_contour_legend_elements  s    
r  zalgorithm, klassmpl2005mpl2014serialthreaded)invalidNc              	   C   sf   t ddgddgg}|d k	r>tj|| d}t|j|sbtn$tt	 tj|| d W 5 Q R X d S )NrC   rH   rD         @	algorithm)
r   rQ   r   rb   r  r   r:   r"   r#   r   )r  klassr   r2   r   r   r   test_algorithm_name  s    r  r  c              	   C   sj   t ddgddgg}tj|| dd | dkr@tj|| dd n&tt tj|| dd W 5 Q R X d S )	NrC   rH   rD   r  F)r  r   r  T)r   rQ   r   rb   r"   r#   r   )r  r   r   r   r   #test_algorithm_supports_corner_mask*  s    r   Zcontour_all_algorithmsc            
      C   s   ddddg} t jd}t t dddt ddd	\}}t d
| t d|  |jddd }t j|t	d}d|d< t j
j||d}tdd\}}t| | D ]8\}}	|j||||	d |j||||	dd ||	 qd S )Nr  r  r  r  i  rY   rC   r   r@   r   r   )r@   r   )scalesizer   T)r   r   r   r?   r  r   )r  rL   )r   r   Zdefault_rngr   rq   r   r   normalr   r   r   rQ   r   r   r  ravelrb   r   	set_title)
Z
algorithmsrngr   r   r   r   rd   re   r   r  r   r   r   test_all_algorithms:  s    $*r'  c                  C   s   d} t dd| }t dd| }t ||\}}t |d  |d  }t |d d  |d d  }|| d }t }|jddd}	|	D ]4}
|
 }||||}|j	|d	d
d |
d qd S )Nr   rk   rD   rl   rH   r?   r8   )Znrowsr   Tr   )r   rK   zSimplest default with labels)r   r   r   rr   r   rP   Z
subfiguresr   r   r1   r%  )r   r   r   ru   rv   rw   rx   r   r   Zfigsfr   r   r   r   r   test_subfigure_clabelM  s     r)  r>   ZsoliddasheddashdotZdottedc              	   C   sf  d}t dd|}t dd|}t ||\}}t |d  |d  }t |d d  |d d  }|| d }t \}	}
|
j|||dd	d
}|
j|ddd |
d |j	d kst
t \}}|j|||dd	| d}|j|ddd |d|   |j	| kst
t \}}|j|||dd	| dd}|j|ddd |d|   |j	| ksbt
d S )Nr   rk   rD   rl   rH   r?   r8   r@   r   rL   r   TrK   r   z0Single color - positive contours solid (default))rL   
linestylesz!Single color - positive contours r+  rL   r.  negative_linestyles)r   r   r   rr   r   r   r   r1   r%  r.  r:   )r>   r   r   r   ru   rv   rw   rx   r   fig1r   CS1fig2r   CS2fig3r   CS3r   r   r   test_linestylesa  s0     
r7  c              	   C   s  d}t dd|}t dd|}t ||\}}t |d  |d  }t |d d  |d d  }|| d }t \}	}
|
j|||dd	d
}|
j|ddd |
d |j	dkst
| tjd< t \}}|j|||dd	d
}|j|ddd |d|  d |j	| kst
t \}}|j|||dd	| d}|j|ddd |d|   |j	| ksjt
t \}}|j|||dd	d| d}|j|ddd |d|   |j	| kst
d S )Nr   rk   rD   rl   rH   r?   r8   r@   r   r,  r   Tr-  z1Single color - negative contours dashed (default)r*  zcontour.negative_linestylez!Single color - negative contours z(using rcParams))rL   r0  r+  r/  )r   r   r   rr   r   r   r   r1   r%  r0  r:   r`   )r>   r   r   r   ru   rv   rw   rx   r   r1  r   r2  r3  r   r4  r5  r   r6  Zfig4Zax4ZCS4r   r   r   test_negative_linestyles  s<     

r8  c                  C   s^   t   } |  }| tdd}|  |  |ksBt	|
  |  |ksZt	d S )Nr   r   )r   rP   r   Zget_childrenr   r   r   r0   r1   r:   remove)r   Zorig_childrenr2   r   r   r   test_contour_remove  s    r:  c                  C   s  t jdd\} }t dd dt}dddgdddgdddgg}t|	 j
	 dgksftt|j
	 dgksttt jj||dj
	 dgkstt|	 j
	 ddd	gkstt|j
	 ddd	gksttt jj||dj
	 ddd	gkst| }t| ||	 j
	 dgks>tt| ||j
	 dgks^tt| ||	 j
	 ddd	gkstt| ||j
	 ddd	gkstd S )
Nr?   r   )r   r   FTr   r   r   r8   )r   r   r/   r   r0   Zastyper   r   r   tolistr+   r:   r   rQ   rb   r$  Z
tricontourZtricontourf)r   r   r   mr   r   r   test_bool_autolevel  s    &",$ (r=  )Fr   platformr%   Z	contourpynumpyr   Znumpy.testingr   r   Z
matplotlibZmplZmatplotlib.testing.decoratorsr   r   r   r   r   Zmatplotlib.colorsr   r	   r"   r   r   markZparametrizer   emptyr)   r3   r<   rR   rj   rz   r   machiner   r   r   r   r   r   r   r   r   r   backendr   r   r   r   r   r   r   r>   contextr   r  r  ZMpl2005ContourGeneratorZMpl2014ContourGeneratorZSerialContourGeneratorZThreadedContourGeneratorr  r   r'  r)  r7  r8  r:  r=  r   r   r   r   <module>   sH  





 

	 
 
!  
  



 

 
 


	

 

 
 

  

)
