o
    Gf<                     @   sT  d dl Zd dlmZ d dlZd dlZd dlmZ d dl	m
Z
mZ e
dgdddd	d
 Ze
dgdddddd Ze
dgdd Zdd Ze dd Ze dd Ze dd Ze
dgdddd Ze
dgddd d! Ze
d"gddd#d$ Ze
d%gddd&d' Ze
d(gddd)d* Ze
d+gddd,d- Ze
d.gddd/d0 Ze
d1gddd2d3 Zed4gd5d6d7 Zed4gd5d8d9 Zd:d; Zd<d= Zd>d? Zd@dA Z dBdC Z!dDdE Z"ed4gd5dFdG Z#ed4gd5dHdI Z$dJdK Z%dLdM Z&dNdO Z'dPdQ Z(ed4gd5dRdS Z)dTdU Z*dVdW Z+dXdY Z,e
dZgddd[d\ Z-d]d^ Z.dS )_    N)assert_allclose)pyplot)image_comparisoncheck_figures_equalZ
polar_axesdefaultg~jt?)styletolc               	   C   s   t ddd} dt j |  }t }|jdd}|j|| ddd	\}|jd
dddd	\}d}| | || }}||g|gd |jd||fddtdddddd |j	ddddd d S )N              ?MbP?      @Tpolarz#ee8d18   )ZcolorZlwr   r   r      z#0000ffr      oza polar annotation)皙?r   zfigure fractionblackr   	facecolorZshrinkleftbaseline)xyxytext
textcoords
arrowpropshorizontalalignmentverticalalignmentxout)Zaxistick1Ontick2On	direction)
nparangepipltfigureadd_subplotplotannotatedicttick_params)rthetafigaxlineZindZthisrZ	thistheta r5   ;lib/python3.10/site-packages/matplotlib/tests/test_polar.pytest_polar_annotations
   s$   
	r7   Zpolar_coordsT)r   Zremove_textr   c                  C   s   t jjdddddd} t }|jdd}||  | |j |j	d	t
jd
 dft
jd dfddtddddddd	 |dd |dd d S )Nr   
      r0         ?)r   alphaZequal)Zaspectzthe top       @      $@r   g      4@r   r   r   r   r   r   T)r   r   Zxycoordsr   r   r   r    Zclip_oni)mplZpatchesZEllipser)   r*   r+   Z
add_artistZset_clip_boxZbboxr-   r&   r(   r.   Zset_xlimset_ylim)elr2   r3   r5   r5   r6   test_polar_coord_annotations,   s"   

rA   zpolar_alignment.pngc                  C   s   t ddd} g d}t }g d}|j|ddd}||  |j|dd	d}|jd
 tdD ]}|j	| j
|| | ddd q2d S )Nr   ih  Z   )r   皙?皙?g333333?皙?r   皙?rG   rE   rE   T
horizontal)r   ZlabelverticalF   r   top)Zangler   r    )r&   r'   r)   r*   add_axesZset_thetagridsZpatchZset_visiblerangeaxesZ
set_rgrids)ZanglesZgrid_valuesr2   ZrectrH   rI   ir5   r5   r6   test_polar_alignmentI   s   

rP   c                  C   sJ   t  } t ddgddg t ddgddg t| jdks#J d	d S )
Nr   rJ   rG   rC   r      g333333?rD   z!More than one polar axes created.)r)   r*   r   lenrN   )r2   r5   r5   r6   test_polar_twice^   s   rS   c                 C   s   | j dd}|tddgddg |tddgddg |j dd}|tdd	gddg |tdd
gddg d S )Nr   
projection   iMrC   rG   rJ      if  )r+   r,   r&   deg2radfig_testfig_refr3   r5   r5   r6   test_polar_wrape   s   r]   c                    s~   dd l m  m     g d}g d}t| j t fdd|D | |jdd}|	t
|| |jdd	 d S )
Nr   g      >@g     F@g      N@     V@r
   r<         @r   c                       g | ]}| j  qS r5   deg.0r!   Zunitsr5   r6   
<listcomp>w       z&test_polar_units_1.<locals>.<listcomp>r   rT   rd   )xlabel)matplotlib.testing.jpl_unitstesting	jpl_unitsregisterr)   r*   numberr   r+   r,   r&   rY   set)r[   r\   xsysr3   r5   rg   r6   test_polar_units_1o   s   rs   c                    s   dd l m  m     g d} fdd|D }g d} fdd|D }t| j tj||ddd	 tt	 j
  jsCJ |jd
d}|t|| |j
tjdj |jddd d S )Nr   r^   c                    rb   r5   rc   re   rg   r5   r6   rh      ri   z&test_polar_units_2.<locals>.<listcomp>r`   c                    rb   r5   )km)rf   yrg   r5   r6   rh      ri   Zradrt   )Z
thetaunitsZrunitsr   rT   z{:.12})rj   Zylabel)rk   rl   rm   rn   r)   r*   ro   r   
isinstancegcaxaxisZget_major_formatterZUnitDblFormatterr+   r,   r&   rY   Zset_major_formatterr>   ZtickerZFuncFormatterformatrp   )r[   r\   rq   Zxs_degrr   Zys_kmr3   r5   rg   r6   test_polar_units_2~   s   rz   Z
polar_rmin)r   c                  C   sZ   t ddd} dt j |  }t }|jg ddd}|||  |d |d	 d S )
Nr   ra   {Gz?rJ   rF   Tr   r<   r:   	r&   r'   r(   r)   r*   rL   r,   set_rmaxset_rminr0   r1   r2   r3   r5   r5   r6   test_polar_rmin      
r   Zpolar_negative_rminc                  C   sZ   t ddd} dt j |  }t }|jg ddd}|||  |d |d d S )Ng      r	   r{   rJ   rF   Tr   r|   r   r5   r5   r6   test_polar_negative_rmin   r   r   Zpolar_roriginc                  C   sd   t ddd} dt j |  }t }|jg ddd}|||  |d |d	 |	d
 d S )Nr   ra   r{   rJ   rF   Tr   r<   r:   r	   )
r&   r'   r(   r)   r*   rL   r,   r}   r~   set_roriginr   r5   r5   r6   test_polar_rorigin   s   

r   zpolar_invertedylim.pngc                  C   s*   t  } | jg ddd}|dd d S )NrF   Tr   rJ   r   )r)   r*   rL   r?   r2   r3   r5   r5   r6   test_polar_invertedylim   s   r   zpolar_invertedylim_rorigin.pngc                  C   sV   t  } | jg ddd}|jd |jddgddgdd |d |d d S )	NrF   Tr   r   rJ   none)cr   )r)   r*   rL   yaxisZset_invertedr,   Zmarginsr   r   r5   r5   r6   test_polar_invertedylim_rorigin   s   
r   Zpolar_theta_positionc                  C   s\   t ddd} dt j |  }t }|jg ddd}|||  |dd	 |d
 d S )Nr   ra   r{   rJ   rF   Tr   ZNW   	clockwise)	r&   r'   r(   r)   r*   rL   r,   Zset_theta_zero_locationset_theta_directionr   r5   r5   r6   test_polar_theta_position   s   r   Zpolar_rlabel_positionc                  C   s.   t  } | jdd}|d |jdd d S )Nr   rT   i;  auto)rotation)r)   r*   r+   Zset_rlabel_positionr/   r   r5   r5   r6   test_polar_rlabel_position   s   
r   Zpolar_theta_wedgec               	   C   s   t ddd} dt j |  }t ddd}t ddd}d	}tjt|t|d
didd\}}t|D ]Z\}}t|D ]Q\}	}
|||	f }|||  ||
k rZ|| |	|
 n||
 |	| |
d |jdd||t|  dd |jjddd |j jjg dd q;q3d S )Nr   ra   r{   rJ   g      .@g     v@r_   g      I@)r"   inZinoutr   T)      )
subplot_kwZfigsizer   r   )r#   r$   r%   r   )Zlabel2Onr   )r   rJ   g      @   r8   )Zsteps)r&   r'   r(   r)   subplotsrR   	enumerater,   Zset_thetaminZset_thetamaxr   r/   r   Zset_tick_paramsrx   Zget_major_locatorbaseZ
set_params)r0   r1   Z
theta_minsZ
theta_maxsZ
DIRECTIONSr2   axsrO   startjendr3   r5   r5   r6   test_polar_theta_limits   s:   




r   Zpng)
extensionsc                 C   sP   | j ddid}|jdd |jdd |j ddid}|d |d d S )	Nr   Tr   r8   )rK   r:   Zbottomr=   r   set_rlimr}   r~   rZ   r5   r5   r6   test_polar_rlim   s   
r   c                 C   sH   | j ddid}|jddgd |j ddid}|d |d d S )Nr   Tr   r:   r8   r   r=   r   rZ   r5   r5   r6   test_polar_rlim_bottom  s
   
r   c                  C   sD   t  jdd} | tdtdd  |  d dks J d S )Nr   rT   r8   r{   r   )r)   r*   r+   r,   r&   r'   get_ylimr3   r5   r5   r6   test_polar_rlim_zero  s   r   c                  C   sj   t jdd t  } |  dkr|  dksJ t d t   t  } |  dkr1|  dks3J d S )Nr   rT   r   r   all)r)   subplotrw   get_rminZget_rmaxcloser   r   r5   r5   r6   test_polar_no_data  s   
 r   c                  C   s2   t jdd t  } | d |  dksJ d S )Nr   rT   logr   )r)   r   rw   
set_rscaler   r   r5   r5   r6   test_polar_default_log_lims&  s   
r   c                  C   sJ   t  jdd} tt | d W d    d S 1 sw   Y  d S )Nr   rT   Zdatalim)r)   r*   r+   pytestraises
ValueErrorZset_adjustabler   r5   r5   r6   !test_polar_not_datalim_adjustable-  s   "r   c                  C   sv   t  } | jdd}|jdd t j|j dd | j  |j	j
d j dks,J |jj
d j dks9J d S )NTr   rC   )r;   F)Zvisibler   )r)   r*   r+   ZgridZsetpr   get_ticklabelscanvasdrawrx   
majorTicksZgridlineZ	get_alphar   r5   r5   r6   test_polar_gridlines3  s   
r   c                  C   sF   t jddid\} }| j  || j }t|jg ddd d S )NrU   r   r   )gyZ@g,ԚG=@g_)Gހ@gR!+|@r   )Zrtol)r)   r   r   r   Zget_tightbboxZget_rendererr   Zextents)r2   r3   Zbbr5   r5   r6   test_get_tightbbox_polar?  s   

r   c                 C   s   | j dddjdgdgdtj ddd	}| j d
ddjdgdgdtj ddd	}|j dddjdgdgdtj ddd	}|j d
ddjdgdgdtj ddd	}d S )Ny   r   rT   r   r   r   r   F)Z	edgecolorZantialiasedz   rJ   rW   )r+   Zbarr&   r(   )r[   r\   Zp1Zp2Zp3Zp4r5   r5   r6   )test_polar_interpolation_steps_constant_rG  s   
r   c                 C   s`   | j dddtjd gddg\}d| _|j ddtdtjd dtddd d S )Nr   rT   r   rJ   r   d   e   )r+   r,   r&   r(   get_path_interpolation_stepslinspace)r[   r\   lr5   r5   r6   )test_polar_interpolation_steps_variable_rU  s
   $
r   c                  C   s   t jdd} | ddtj  | jddd tjtdd	 | dd
tj  W d    n1 s1w   Y  tjtdd	 | jddd W d    d S 1 sPw   Y  d S )Nr   rT   r   rJ   r   i  )ZthetaminZthetamaxz+angle range must be less than a full circle)matchr   i  )r)   r   set_thetalimr&   r(   r   r   r   r   r5   r5   r6   test_thetalim_valid_invalid]  s   "r   c                  C   sj   t jdd} | dd tt|  |  fdksJ | d tt|  |  fdks3J d S )Nr   rT   r   r   r   )rJ   r   )r)   r   r   tupler&   ZradiansZget_thetaminZget_thetamaxr   r5   r5   r6   test_thetalim_argsi  s
   "
&r   c                  C   s|   t jdddid\} }| D ]	}|dtj q| D ]}t|j 	 }t
d|v s2J t
d|vs;J qd S )NzAAAABB.rU   r   r   r   rB   r   )r)   subplot_mosaicvaluesr   r&   r(   Zdegreesrx   Zget_majorticklocstolistr   Zapprox)r2   r   r3   Zticklocsr5   r5   r6   test_default_thetalocatorq  s   
r   c                  C   s4   t jdd} | dtjd }| jdksJ d S )Nr   rT   r   rQ   r   )r)   r   axvspanr&   r(   r   r   )r3   spanr5   r5   r6   test_axvspan  s   r   c                 C   s`   | j dddddid}dD ]	}|j|   q|j dddddid}dD ]	}|j|   q$d S )NrJ   TrU   r   )sharexr   )r   r   r   )shareyr   )r   Zflatremove)r\   r[   r   rO   r5   r5   r6   test_remove_shared_polar  s   r   c                  C   s   t jddddiddd\} }| j  |d jjd  sJ |d jjd  s+J t jdddiddd\} }| j  |d	 jjd  sIJ |d	 jjd  sUJ d S )
NrJ   rU   r   T)r   r   r   r   r   zab
cdb)	r)   r   r   r   rx   r   Zget_visibler   r   )r2   r   r5   r5   r6   "test_shared_polar_keeps_ticklabels  s   



r   c                  C   sD   t jdd} | dd | d | ddg |  dks J d S )	Nr   rT   r   r   r:   rG   rC   )r   rC   )r)   r   r   Zaxvliner,   r   r   r5   r5   r6   (test_axvline_axvspan_do_not_modify_rlims  s
   
r   c                  C   s   t jdd} | dddksJ | dddksJ | ddd	ks$J | ddd
ks.J | dddks8J | dddksBJ | dddksLJ | dddksVJ | dddks`J d S )Nr   rT   r   g{Gzt?u   θ=0.0π (0°), r=0.005rG   u   θ=0.00π (0°), r=0.100r   u   θ=0.000π (0.0°), r=1.000u   θ=0.3π (57°), r=0.005u   θ=0.32π (57°), r=0.100u   θ=0.318π (57.3°), r=1.000rJ   u   θ=0.6π (115°), r=0.005u   θ=0.64π (115°), r=0.100u   θ=0.637π (114.6°), r=1.000)r)   r   Zformat_coordr   r5   r5   r6   test_cursor_precision  s   r   zpolar_log.pngc                  C   sX   t  } | jdd}|d |dd d}|tddtj |t	dd| d S )	NTr   r   r   i  r   r   rJ   )
r)   r*   r+   r   r   r,   r&   r   r(   Zlogspace)r2   r3   nr5   r5   r6   test_polar_log  s   
*r   c                  C   sN   t  } | jdd}|tj tj dd |j D }|g dks%J d S )Nr   rT   c                 S   s   g | ]}|  qS r5   )Zget_text)rf   r   r5   r5   r6   rh     s    z-test_polar_neg_theta_lims.<locals>.<listcomp>)u   -180°u   -135°u   -90°u   -45°u   0°u   45°u   90°u   135°)r)   r*   r+   r   r&   r(   rx   r   )r2   r3   labelsr5   r5   r6   test_polar_neg_theta_lims  s
   r   )/Znumpyr&   Znumpy.testingr   r   Z
matplotlibr>   r   r)   Zmatplotlib.testing.decoratorsr   r   r7   rA   rP   rS   r]   rs   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r5   r5   r5   r6   <module>   s~    

!


	










 



	






