U
    \	¸aË.  ã                   @   sò  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!ed4gd5dDdE„ ƒZ"ed4gd5dFdG„ ƒZ#dHdI„ Z$dJdK„ Z%dS )Lé    N)Úassert_allclose)Úpyplot)Úimage_comparisonÚcheck_figures_equalZ
polar_axesÚdefaultgú~j¼t“ˆ?)Ú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é   )ÚcolorZlw©r   r   ©r   é   z#0000ffr   é   Úoza polar annotation)çš™™™™™©?r   zfigure fractionÚblackr   ©Ú	facecolorÚ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ÚlineÚindZthisrZ	thistheta© r8   ú?/tmp/pip-unpacked-wheel-wjyw_3jo/matplotlib/tests/test_polar.pyÚtest_polar_annotations
   s$    
ú	r:   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   é
   é   r2   ç      à?)r   ÚalphaÚ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*   r0   Zset_xlimÚset_ylim)Úelr4   r5   r8   r8   r9   Útest_polar_coord_annotations,   s"    

ørE   zpolar_alignment.pngc                  C   s–   t  ddd¡} ddddddg}t ¡ }d	d	ddg}|j|d
dd}| | ¡ |j|d
dd}|j d¡ tdƒD ] }|j	| j
|| | ddd qpd S )Nr   ih  éZ   çš™™™™™É?çš™™™™™Ù?g333333ã?çš™™™™™é?r   çš™™™™™¹?TÚ
horizontal)r   ÚlabelÚverticalFé   r   Útop)Zangler!   r"   )r(   r)   r+   r,   Úadd_axesZset_thetagridsÚpatchZset_visibleÚrangeÚaxesZ
set_rgrids)ZanglesZgrid_valuesr4   ZrectrK   rM   Úir8   r8   r9   Útest_polar_alignmentI   s    

  þrU   c                  C   sJ   t  ¡ } t  ddgddg¡ t  ddgddg¡ t| jƒdksFtd	ƒ‚d S )
Nr   rN   rJ   rG   r   é   g333333Ó?rH   z!More than one polar axes created.)r+   r,   r   ÚlenrS   ÚAssertionError)r4   r8   r8   r9   Útest_polar_twice^   s    rY   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é³   iMÿÿÿrG   rJ   rN   éþÿÿÿéµ   if  )r-   r.   r(   Údeg2rad©Úfig_testÚfig_refr5   r8   r8   r9   Útest_polar_wrape   s    rc   c                    s†   dd l m  m‰  ˆ  ¡  ddddg}dddd	g}t | j¡ t ‡ fd
d„|D ƒ|¡ |jdd}| 	t
 |¡|¡ |jdd d S )Nr   ç      >@ç     €F@ç      N@ç     €V@r
   r@   ç      @r   c                    s   g | ]}|ˆ j  ‘qS r8   ©Údeg©Ú.0r#   ©Zunitsr8   r9   Ú
<listcomp>w   s     z&test_polar_units_1.<locals>.<listcomp>r   rZ   rj   )Úxlabel)Úmatplotlib.testing.jpl_unitsÚtestingÚ	jpl_unitsÚregisterr+   r,   Únumberr   r-   r.   r(   r_   Úset)ra   rb   ÚxsÚysr5   r8   rm   r9   Útest_polar_units_1o   s    rx   c                    sÔ   dd l m  m‰  ˆ  ¡  ddddg}‡ fdd„|D ƒ}dd	d
dg}‡ fdd„|D ƒ}t | j¡ tj||ddd tt 	¡ j
 ¡ ˆ jƒsŽt‚|jdd}| t |¡|¡ |j
 tj dj¡¡ |jddd d S )Nr   rd   re   rf   rg   c                    s   g | ]}|ˆ j  ‘qS r8   ri   rk   rm   r8   r9   rn   ƒ   s     z&test_polar_units_2.<locals>.<listcomp>r
   r@   rh   r   c                    s   g | ]}|ˆ j  ‘qS r8   )Úkm)rl   Úyrm   r8   r9   rn   …   s     Zradry   )Z
thetaunitsZrunitsr   rZ   z{:.12})ro   Zylabel)rp   rq   rr   rs   r+   r,   rt   r   Ú
isinstanceÚgcaÚxaxisZget_major_formatterZUnitDblFormatterrX   r-   r.   r(   r_   Zset_major_formatterrB   ZtickerZFuncFormatterÚformatru   )ra   rb   rv   Zxs_degrw   Zys_kmr5   r8   rm   r9   Útest_polar_units_2~   s    ÿr   Z
polar_rmin)r   c                  C   s^   t  ddd¡} dt j |  }t ¡ }|jddddgdd}| || ¡ | d	¡ | d
¡ d S )Nr   rh   ç{®Gáz„?rN   rJ   rI   Tr   r@   r=   ©	r(   r)   r*   r+   r,   rP   r.   Úset_rmaxÚset_rmin©r2   r3   r4   r5   r8   r8   r9   Útest_polar_rmin“   s    
r…   Zpolar_negative_rminc                  C   s^   t  ddd¡} dt j |  }t ¡ }|jddddgdd}| || ¡ | d¡ | d¡ d S )	Ng      Àr	   r€   rN   rJ   rI   Tr   r   r„   r8   r8   r9   Útest_polar_negative_rminŸ   s    
r†   Zpolar_roriginc                  C   sh   t  ddd¡} dt j |  }t ¡ }|jddddgdd}| || ¡ | d	¡ | d
¡ | 	d¡ d S )Nr   rh   r€   rN   rJ   rI   Tr   r@   r=   r	   )
r(   r)   r*   r+   r,   rP   r.   r‚   rƒ   Úset_roriginr„   r8   r8   r9   Útest_polar_rorigin«   s    

rˆ   zpolar_invertedylim.pngc                  C   s.   t  ¡ } | jddddgdd}| dd¡ d S )NrJ   rI   Tr   rN   r   )r+   r,   rP   rC   ©r4   r5   r8   r8   r9   Útest_polar_invertedylim¸   s    rŠ   zpolar_invertedylim_rorigin.pngc                  C   sZ   t  ¡ } | jddddgdd}|j d¡ |jddgddgdd | d¡ | d	¡ d S )
NrJ   rI   Tr   r   rN   Únone)Úcr   )r+   r,   rP   ÚyaxisZset_invertedr.   Zmarginsr‡   r‰   r8   r8   r9   Útest_polar_invertedylim_rorigin¿   s    
rŽ   Zpolar_theta_positionc                  C   s`   t  ddd¡} dt j |  }t ¡ }|jddddgdd}| || ¡ | d	d
¡ | d¡ d S )Nr   rh   r€   rN   rJ   rI   Tr   ZNWé   Ú	clockwise)	r(   r)   r*   r+   r,   rP   r.   Zset_theta_zero_locationÚset_theta_directionr„   r8   r8   r9   Útest_polar_theta_positionË   s    r’   Zpolar_rlabel_positionc                  C   s.   t  ¡ } | jdd}| d¡ |jdd d S )Nr   rZ   i;  Úauto)Úrotation)r+   r,   r-   Zset_rlabel_positionr1   r‰   r8   r8   r9   Ú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 ]œ\}}t|ƒD ]Š\}	}
|||	f }| || ¡ ||
k r´| |¡ | 	|
¡ n| |
¡ | 	|¡ | 
d¡ |jdd||t|ƒ  dd |jjddd qvqfd S )Nr   rh   r€   rN   g      .@g     v@rg   g      I@)r$   ÚinZinoutr   T)é   é   )Ú
subplot_kwZfigsizer   r“   )r%   r&   r'   r”   )Zlabel2Onr”   )r(   r)   r*   r+   ÚsubplotsrW   Ú	enumerater.   Zset_thetaminZset_thetamaxr‘   r1   r   Zset_tick_params)r2   r3   Z
theta_minsZ
theta_maxsZ
DIRECTIONSr4   ZaxsrT   ÚstartÚjÚendr5   r8   r8   r9   Útest_polar_theta_limitsß   s0    þ




þ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™   r;   )rO   r=   ©ZbottomrA   ©rš   Zset_rlimr‚   rƒ   r`   r8   r8   r9   Ú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=   r;   r¢   rA   r£   r`   r8   r8   r9   Útest_polar_rlim_bottom	  s
    
r¥   c                  C   sD   t  ¡ jdd} |  t d¡t d¡d ¡ |  ¡ d dks@t‚d S )Nr   rZ   r;   r€   r   )r+   r,   r-   r.   r(   r)   Zget_ylimrX   ©r5   r8   r8   r9   Útest_polar_rlim_zero  s    r§   c                  C   sj   t jdd t  ¡ } |  ¡ dkr,|  ¡ dks0t‚t  d¡ t  ¡  t  ¡ } |  ¡ dkrb|  ¡ dksft‚d S )Nr   rZ   r   r   Úall)r+   Úsubplotr|   Zget_rminZget_rmaxrX   Úcloser   r¦   r8   r8   r9   Útest_polar_no_data  s    
r«   c               	   C   s4   t  ¡ jdd} t t¡ |  d¡ W 5 Q R X d S )Nr   rZ   Zdatalim)r+   r,   r-   ÚpytestÚraisesÚ
ValueErrorZset_adjustabler¦   r8   r8   r9   Ú!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sXt‚|jj
d j ¡ dksrt‚d S )NTr   rG   )r>   F)Zvisibler   )r+   r,   r-   ZgridÚsetpr   Zget_ticklabelsÚcanvasÚdrawr}   Z
majorTicksZgridlineZ	get_alpharX   r‰   r8   r8   r9   Útest_polar_gridlines*  s    
r³   c                  C   sJ   t jddid\} }| j ¡  | | j ¡ ¡}t|jddddgdd	 d S )
Nr[   r   r¡   gµ¦yÇñZ@g,ÔšæG=@g_)ËGÞ€@g½R–!Ž+|@r   )Zrtol)r+   rš   r±   r²   Zget_tightbboxZget_rendererr   Zextents)r4   r5   Zbbr8   r8   r9   Útest_get_tightbbox_polar6  s    
 
 ÿr´   c                 C   s¼   | j dddjdgdgdtj dd}| j d	ddjdgdgd
tj dd}|j dddjdgdgdtj dd}|j d	ddjdgdgdtj dd}||||fD ]}tj|dd q¤d S )Néy   r   rZ   r   r   r   r‹   )Z	edgecoloréz   éýÿÿÿrN   r]   F)Zantialiased)r-   Úbarr(   r*   r+   r°   )ra   rb   Úp1Úp2Zp3Zp4Úpr8   r8   r9   Ú)test_polar_interpolation_steps_constant_r>  s4       ÿ   ÿ   ÿ   ÿ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   rZ   r   rN   r   éd   ée   )r-   r.   r(   r*   Úget_pathZ_interpolation_stepsZlinspace)ra   rb   Úlr8   r8   r9   Ú)test_polar_interpolation_steps_variable_rN  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 5 Q R X tjtdd	 | jddd W 5 Q R X d S )Nr   rZ   r   rN   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¦   r8   r8   r9   Útest_thetalim_valid_invalidV  s    ÿÿrÄ   c                  C   sj   t jdd} |  dd¡ tt |  ¡ |  ¡ f¡ƒdks:t‚|  d¡ tt |  ¡ |  ¡ f¡ƒdksft‚d S )Nr   rZ   r   r   r   )rN   r   )	r+   r©   rÃ   Útupler(   ÚradiansZget_thetaminZget_thetamaxrX   r¦   r8   r8   r9   Útest_thetalim_argsb  s
    "
rÇ   )&Znumpyr(   Znumpy.testingr   r¬   Z
matplotlibrB   r   r+   Zmatplotlib.testing.decoratorsr   r   r:   rE   rU   rY   rc   rx   r   r…   r†   rˆ   rŠ   rŽ   r’   r•   rŸ   r¤   r¥   r§   r«   r¯   r³   r´   r¼   rÁ   rÄ   rÇ   r8   r8   r8   r9   Ú<module>   sf   
!
ÿ


	














	



