a
    ضaB                     @   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&d'd(d) Ze
d*gd%d+d,d- Ze
d.gd/d&d'd0d1 Ze
d2gd%d&e d3krd nd4d5d6d7 Z e
d8d9gd%d+d:d; Z!d<d= Z"d>d? Z#ejd@dAe$dBfdCe%dDfd ggd ggg gdd%d fe%dEfd ggd ggd ggdd%d fe%dFfg edG&dHgdI d ggd%d R e%dJfgdKdL Z'dMdN Z(dOdP Z)ejdQg dRdSdT Z*e
dUgd%d&dVd5dWdX Z+e
dYgd%d&dZd5d[d\ Z,e
d]gd^gd%d&d_d`da Z-ejdbg dcddde Z.ej/dfdgdh Z0e
digd^gd%djdkdl Z1dmdn Z2e
dogd^gd%djdpdq Z3e
drgd^gd%djdsdt Z4ej56dudvdw Z7dS )x    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   m/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/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   sN   t  \}}tjtt|d |j|   W d    n1 s@0    Y  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   sr   t d} t jd}t \}}tt"}|j| | |g d W d    n1 sT0    Y  t	|dksnJ d S )Nr	   r   levels   )
r   r   r   r   r   r   warnsUserWarningr   lenr   r   r   r   recordr   r   r   test_contour_empty_levels?   s    
0r/   c                  C   s`   t dd} t \}}|| d}t|jdks:J |j| dd}|j|jk s\J d S )N   r         r)   r'   )	r   r   reshaper   r   r   r,   r(   all)r   r   r   Zcs1Zcs2r   r   r   test_contour_NlevelsJ   s    r6   c                  C   s   t d} t d}t \}}ddi}tt2}|j| | |dgd}|j	||d W d    n1 sj0    Y  t
|dksJ d S )Nr	   r         ?z%1.2fr'   )fmtr)   )r   r   Zzerosr   r   r   r*   r+   r   clabelr,   )r   r   r   r   r8   r.   csr   r   r   test_contour_badlevel_fmtU   s    

,r;   c                  C   sl   t d} t d}t \}}tt}|| | | W d    n1 sN0    Y  t	|dkshJ d S )Nr	   r   r)   )
r   r   Zonesr   r   r   r*   r+   r   r,   r-   r   r   r   test_contour_uniform_ze   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 	g d}tj
||d t 	g d	}tj
||d
dd d S )Nr   r      )   r?      )figsizeZdpi))r7         @)r7   皙@)r7         @)manual))       @rC   )rG   rD   )rG   rE   small)rg)rF   Zfontsizecolors)r   r   r   maxdstackabsr   figurer   arrayr9   )r   r   r   r:   Zptsr   r   r   test_contour_manual_labelsp   s     rQ   z$contour_manual_colors_and_levels.png)r=   c                  C   s   dt jd< t dd\} }tddd}g d}g d}t|jD ]\}}|d d	k}g d
|d  }|r|dv rzdnd }	|dv rdnd }
|j|||	|
 ||d}n|j	||d d ||d}t j
||d qFd S )NFpcolormesh.snapr?   r2   r0   r   )redyellowZpinkblueblack)r?   r2      r           )neitherminrL   both)rL   rY   r)   )rZ   rY   )rK   r(   extendr   )r   rcParamsr   r   r   r4   	enumerateZflatcontourfr   colorbar)_axsdatarK   r(   ir   filledr]   Zfirst_colorZ
last_colorcr   r   r   $test_given_colors_levels_and_extends}   s$    
ri   zcontour_datetime_axis.pngFc                     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\(\?g333333?)ZhspacetopZbottomi  r)   c                    s   g | ]} t j|d  qS ))days)datetime	timedelta).0dbaser   r   
<listcomp>       z.test_contour_datetime_axis.<locals>.<listcomp>         r   )Zaxis      right   )r   rO   subplots_adjustrl   r   rP   ranger   r   Zsubplotr   ra   repeatZnewaxisZget_axesZget_xticklabelsZset_haZset_rotation)r   r   r   Zz1Zz2r   r   labelr   rp   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\}}	|	|||}
g d}g d}|
  |D ]\}}|
j	||dd d q|D ]\}}|
j	||ddd qd S )Ng?g      rC   g       rG   r?   r)   g      ?      ?      $@))      )ig  i"  )i	  i  ))r   )r   g      )gffffff@r)   T)inlineZ	transformF)
r   r   r   exppir   r   r   r9   Zadd_label_near)deltar   r   XYZZ1ZZ2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?r7   r)   r   rG      rW   mask)FTcorner_mask)r   r   seedr   linspacecossinrandmarP   r   rO   ra   )nZ
mask_levelZ	noise_ampr   r   r   r   r   r   r   r   test_corner_mask   s    $.r   c                  C   sV   ddgddgg} t   tt  t | ddg W d    n1 sH0    Y  d S )Ng?g333333?r   ffffff?r7   rX   )r   rO   r   r    
ValueErrorra   )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 )	Nr0   r1   r2   T)ZnbinsZ	symmetric)locatorir3   )	r   r   r4   r   ZMaxNLocatorra   r   r(   r   )r   r   r:   r   r   r   test_contourf_symmetric_locator   s    r   zargs, cls, messager   z,function takes exactly 6 arguments (0 given))r)   r?   r   r2   r3   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 arraysr2   r?   r?   r   zCIf mask is set it must be a 2D array with the same dimensions as x.c                 C   sP   ddl m} tj|t|d tjj|   W d    n1 sB0    Y  d S )Nr   _contourr   )
matplotlibr   r   r    r"   r#   mplQuadContourGenerator)r$   clsr%   r   r   r   r   test_internal_cpp_api   s    r   c                  C   sp   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    n1 sb0    Y  d S )	Nr   r   r)   r?   r   Tz(filled contour levels must be increasingr   )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 )Nr   r?   r2   )r   r   r   hypotr   rO   r   r9   )r   r   rI   r:   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 u rd| }n|}|D ]}| |ksJ q|D ]}| |ksJ qd S )Nr   r   r?   )Zncols)zorder)r   use_clabeltext)r   r   r   rL   rM   rN   r   r   r   ra   r9   Z
get_zorder)r   Zcontour_zorderZclabel_zorderr   r   r   r   ax1ax2r:   Z	cs_filledZclabels1Zclabels2Zexpected_clabel_zorderr9   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sJ t j|	|d}|j dksJ t j|
|d}d S )NFrR   r)   r   )r   r3   rB   g?r   )leftry   g      g      #@i  r   rz   (   g      g      @r   )ZvminZvmax)normrY   )r(   r   r]   r[   r^   )g:0yE>g    _B)-C6?g    .A)r   r_   r   r{   r   r   powerr4   r   ra   r   rZ   rL   rb   r   get_ylim)r   r   r   Zax3Zdata_expre   Z
levels_expr(   Zc1c2c3cbr   r   r   test_contourf_log_extension7  s.    
r   zcontour_addlines.pngg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 )
NFrR   i,N,r   i'  i  gd]Kȓ\@g6>W'z@r   )r   r_   r   r   r   r   r   Z
pcolormeshr   rb   	add_linesr   r   r   )r   r   r   Zpcmcontr   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| g d	d
}|j||dd |d }|j| g d	d
}|j||dd d S )NFrR      r2   r@   r)   r?   r   )r?   r2   r@   r   rt   r'   Zproportional)r   spacinguniform)r   r_   r   r   r4   r   ra   rb   )r   r   rd   r   r:   r   r   r   test_contour_unevenn  s    
r   zCrc_lines_linewidth, rc_contour_linewidth, call_linewidths, expected))Gz?NNr   )r   (\@Nr   )r   r   Gz@r   c                 C   sv   t | |ddR t \}}tddd}|j||d}|jd d |ksTJ W d    n1 sh0    Y  d S )N)zlines.linewidthzcontour.linewidth)rcr0   r2   r   )
linewidthsr   )r   r   r   r   r   r4   r   Ztlinewidths)Zrc_lines_linewidthZrc_contour_linewidthZcall_linewidthsexpectedr   r   r   r:   r   r   r   test_contour_linewidth~  s    	r   Zpdfc                   C   s    t t ddgddgg d S )Nr)   r?   r   r2   )r   r9   r   r   r   r   r   test_label_nonagg  s    r   Zcontour_closed_line_loop)r   r   r=   c                  C   s^   g dg dg dg dg} t jdd\}}|j| dgdgdd	 |d
d |d
d d S )N)r   r   r   )r   r?   r   )r?   r)   r?   r   r   r   rt   r   )r   alphagg @g@)r   r   r   Zset_xlimZset_ylim)r   r   r   r   r   r   test_contour_closed_line_loop  s
    r   c                  C   sx   t ddgddg\} }| | }t \}}|| ||}|| ||}|j|jksXJ |||}|j|jkstJ d S )NrX   r7   )r   r   r   r   ra   r   Z_contour_generator)r   r   r   r   r   Zqcs1Zqcs2Zqcs3r   r   r   test_quadcontourset_reuse  s    r   Zcontour_manualc            
      C   sr  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}| |g d
||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}g dg}	| |ddg|g|	gd|d | |dg|g|	gddd d S )Nr   )
ContourSet)r2   r2   r   Zviridisr?   r)   r   r2   r   r)   r?   T)rg   cmaprI   k)r   rK   r   r3   r@   )
r)   r?   r?   r?   O   r)   r?   r?   r?   r   )rK   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g dg d\}}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@   r3   r   )r   r)   r?   r   r2   r   g333333?r?   r)   )ZdtypeT)r)   r)   )r)   r   r   r   r   )r   rK   )r   r   r   r   Z
zeros_likeboolr   rP   ra   rb   r   r   )	r   r   r   r   r   r   rg   Zcbarlinesr   r   r   &test_contour_line_start_on_corner_edge  s    
r   defaultc                  C   sZ   t   } t jtdddddg dd}| | dd | jD h d	ksVJ d S )
Ngư>r   d   r   )gh㈵>gh㈵>gh㈵?r'   c                 S   s   h | ]}|  qS r   )Zget_text)rn   textr   r   r   	<setcomp>  rs   z<test_contour_autolabel_beyond_powerlimits.<locals>.<setcomp>>   z4.00z0.25z1.00)	r   rO   Zadd_subplotr   r   Z	geomspacer4   r9   Ztexts)r   r:   r   r   r   )test_contour_autolabel_beyond_powerlimits  s    
r   )8rl   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/   r6   r;   r<   rQ   ri   r   machiner   r   r   r   r!   r   r4   r   r   r   r   r   r   r   r   backendr   r   r   r   r   r>   contextr   r   r   r   r   <module>   s   






,
		

!









