o
    :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   ?/usr/lib/python3/dist-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   sP   t  \}}tjtt|d |j|   W d    d S 1 s!w   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 s*w   Y  t	|dks7J 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   
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}|j| | |dgd}|j	||d W d    n1 s5w   Y  t
|dksBJ 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 s'w   Y  t	|dks4J 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   Z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    rP   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 ]F\}}|d d	k}g d
|d  }|rU|dv r=dnd }	|dv rEdnd }
|j|||	|
 ||d}n|j	||d d ||d}t j
||d q#d S )NFpcolormesh.snapr?   r2   r0   r   )ZredZyellowZpinkZblueZblack)r?   r2      r           )neitherminrK   both)rK   rT   r)   )rU   rT   )rJ   r(   extendr   )r   rcParamsr   r   r   r4   	enumerateZflatcontourfr   colorbar)_axsdatarJ   r(   ir   filledrX   Zfirst_colorZ
last_colorcr   r   r   $test_given_colors_levels_and_extends}   s&   
rd   zcontour_datetime_axis.pngFc                     s8  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 qqd S )Ng?g\(\?g333333?)ZhspacetopZbottomi  r)   c                    s   g | ]
} t j|d  qS ))Zdays)datetimeZ	timedelta).0dbaser   r   
<listcomp>   s    z.test_contour_datetime_axis.<locals>.<listcomp>         r   )Zaxis      right   )r   rN   subplots_adjustrf   r   rO   ranger   r   Zsubplotr   r\   repeatZnewaxisZget_axesZget_xticklabelsZset_haZset_rotation)r   r   r   Zz1Zz2r   r   Zlabelr   ri   r   test_contour_datetime_axis   s.   





rv   z!contour_test_label_transforms.pngZ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 qm|D ]\}}|
j	||ddd q}d S )Ng?g      rC   g       rG   r?   r)   g      ?      ?      $@))      )ig  i"  )i	  i  ))rw   )r   g      )gffffff@r)   T)ZinlineZ	transformF)
r   r   r   ZexpZpir   r   r   r9   Zadd_label_near)Zdeltar   r   XYZZ1ZZ2Zr   r   Z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 qId S )N<   ffffff?r7   r)   r   rG      rR   mask)FTcorner_mask)r   r   seedr   linspaceZcosZsinrandmarO   r   rN   r\   )nZ
mask_levelZ	noise_ampr   r   r   r   r   r   r   r   test_corner_mask   s   $.r   c                  C   sX   ddgddgg} t   tt t | ddg W d    d S 1 s%w   Y  d S )Ng?g333333?rw   ffffff?r7   rS   )r   rN   r   r    
ValueErrorr\   )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MaxNLocatorr\   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   sR   ddl m} tj|t|d tjj|   W d    d S 1 s"w   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   sr   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    d S 1 s2w   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   Zhypotr   rN   r   r9   )r   r   rH   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 rRd| }n|}|D ]
}| |ks`J qV|D ]
}| |ksmJ qcd S )Nr   r   r?   )Zncols)zorder)r   use_clabeltext)r   r   r   rK   rL   rM   r   r   r   r\   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swJ t j|	|d}|j dksJ t j|
|d}d S )NFrQ   r)   r   )r   r3   rB   g?r   )leftrq   g      g      #@i  r   rr   (   g      g      @rx   )ZvminZvmax)normrT   )r(   r   rX   rV   rY   )g:0yE>g    _B)-C6?g    .A)r   rZ   r   rs   r   r   Zpowerr4   r   r\   r   rU   rK   r]   r   get_ylim)r   r   r   Zax3Zdata_expr`   Z
levels_expr(   Zc1Zc2Z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 )
NFrQ   i,N,r   i'  i  gd]Kȓ\@g6>W'z@r   )r   rZ   r   r   r   r   r   Z
pcolormeshr   r]   	add_linesr   r   r   )r   r   r|   ZpcmZ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 )NFrQ      r2   r@   r)   r?   r   )r?   r2   r@   r   rl   r'   Zproportional)r   ZspacingZuniform)r   rZ   r   r   r4   r   r\   r]   )r   r   r_   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   sx   t | |dd* t \}}tddd}|j||d}|jd d |ks*J W d    d S 1 s5w   Y  d S )N)zlines.linewidthzcontour.linewidth)Zrcr0   r2   r   )
linewidthsr   )r   r   r   r   r   r4   r   Ztlinewidths)Zrc_lines_linewidthZrc_contour_linewidthZcall_linewidthsZ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   rw   rl   r   )r   Z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s,J |||}|j|jks:J d S )NrS   r7   )r   r   r   r   r\   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)rb   cmaprH   k)r   rJ   r   r3   r@   )
r)   r?   r?   r?   O   r)   r?   r?   r?   r   )rJ   r   )Zmatplotlib.contourr   r   r   )
r   r   r   r   Zlines0Zlines1Zfilled01Zfilled12ZsegsZ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   rJ   )r   r   r   r   Z
zeros_likeboolr   rO   r\   r]   r   r   )	r   r   r   r   r   r   rb   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s+J d S )
Ngư>r   d   r   )gh㈵>gh㈵>gh㈵?r'   c                 S   s   h | ]}|  qS r   )Zget_text)rg   textr   r   r   	<setcomp>  s    z<test_contour_autolabel_beyond_powerlimits.<locals>.<setcomp>>   0.251.004.00)	r   rN   Zadd_subplotr   r   Z	geomspacer4   r9   Ztexts)r   r:   r   r   r   )test_contour_autolabel_beyond_powerlimits  s   
 r   )8rf   platformr"   Znumpyr   Znumpy.testingr   r   r   Zmatplotlib.testing.decoratorsr   r   r   r   Zmatplotlib.colorsr   r   r   r   ZmarkZparametrizer   emptyr&   r/   r6   r;   r<   rP   rd   rv   machiner   r   r   r   r!   r   r4   r   r   r   r   r   r   r   r   Zbackendr   r   r   r   r   r>   contextr   r   r   r   r   <module>   s    






,
		

!









