U
    \	¸a1$  ã                   @   s¨  d Z ddlZddlZddlmZ ddlmZ 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 ddlmZ ddlmZ ddlmZmZ d	d
„ Ze
jjdddd„ ƒZdd„ Zedgdddd„ ƒZdd„ Zdd„ Z dd„ Z!dd„ Z"edgdd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'd-d.„ Z(ed/gd0d1d2d3„ ƒZ)d4d5„ Z*eƒ d6d7„ ƒZ+ed8d9d:d;„ ƒZ,d<d=„ Z-eƒ d>d?„ ƒZ.d@dA„ Z/dS )Bz%
Tests specific to the lines module.
é    N)ÚSimpleNamespace)Úcycler)Úassert_array_equal)ÚMarkerStyle)ÚPath)Úimage_comparisonÚcheck_figures_equalc                  C   sH   d\} }t  ddg¡t  ddg¡ }}d}tt | ||||¡dgƒ dS )zTest a problematic case.)i)  i†  g     H@g     ÀW@g     ˜@gÃõ(\Â@r   N)ÚnpÚarrayr   ÚmlinesZsegment_hits)ZcxÚcyÚxÚyZradius© r   ú?/tmp/pip-unpacked-wheel-wjyw_3jo/matplotlib/tests/test_lines.pyÚtest_segment_hits   s    r   é   )Zrerunsc            
      C   sœ   d} t  dd| ¡}t jj| d}t ¡ }t ¡ }t ||¡}| 	d¡ t
tj|jjdddƒ}| |¡ t
tj|jjdddƒ}|| }d}	||	k s˜t‚d	S )
ac  
    GitHub issue #1256 identified a bug in Line.draw method

    Despite visibility attribute set to False, the draw method was not
    returning early enough and some pre-rendering code was executed
    though not necessary.

    Consequence was an excessive draw time for invisible Line instances
    holding a large number of points (Npts> 10**6)
    i€–˜ r   é   )ÚsizeFr   )ÚnumberÚrepeaté   N)r	   ÚlinspaceÚrandomÚnormalÚpltÚfigureZsubplotr   ÚLine2DZset_visibleÚminÚtimeitr   ÚcanvasÚdrawZadd_lineÚAssertionError)
ÚNr   r   ÚfigÚaxÚlZ	t_no_lineZt_invisible_lineZslowdown_factorZslowdown_thresholdr   r   r   Útest_invisible_Line_rendering    s    

r'   c                  C   s6   t  ¡ \} }tj d¡ |jtj dd¡dgd d S ©Nr   é   é   ©r   )r   r   )Z
linestyles©r   Úsubplotsr	   r   ÚseedZcontourZrandn©r$   r%   r   r   r   Útest_set_line_coll_dashL   s    r0   Zline_dashesT)Úremove_textc                  C   s$   t  ¡ \} }|jtdƒddd d S )Né
   r+   é   ©Ú	linestyleÚlw)r   r-   ÚplotÚranger/   r   r   r   Útest_line_dashesT   s    r9   c                  C   st   t  ¡ \} }|jtdƒdd |jtdƒdd |jtdƒdd |jtdƒdd |jtdƒdd | j ¡  d S )Nr2   Únone)ÚcolorÚrz.3)r   r   r   r   )r   r   r   ©r   r-   r7   r8   r    r!   r/   r   r   r   Útest_line_colors[   s    r>   c               	   C   s0   t  g g ¡} t t¡ |  d¡ W 5 Q R X d S ©NZfoobar)r   r   ÚpytestÚraisesÚ
ValueErrorZ	set_color©Úliner   r   r   Útest_valid_colorse   s    rE   c                  C   s6   t  ¡ \} }dD ]}|jtdƒ|d q| j ¡  d S )N)ú-Zsolidz--Údashedz-.Údashdotú:Údottedr2   )r5   r=   )r$   r%   Úlsr   r   r   Útest_linestyle_variantsk   s    rL   c               	   C   s0   t  g g ¡} t t¡ |  d¡ W 5 Q R X d S )NZaardvark)r   r   r@   rA   rB   Zset_linestylerC   r   r   r   Útest_valid_linestyless   s    rM   zdrawstyle_variants.pngc                  C   sX   t  d¡\} }dddddd g}t|j|ƒD ](\}}|jtdƒ|d |jd	d	d
 q*d S )Né   Údefaultz	steps-midú	steps-prez
steps-postZstepsiÐ  )Z	drawstyle)r   r   )ZxlimZylim)r   r-   ÚzipÚflatr7   r8   Úset)r$   ZaxsZdssr%   Zdsr   r   r   Útest_drawstyle_variantsy   s
    rT   c               	   C   s0   t  g g ¡} t t¡ |  d¡ W 5 Q R X d S r?   )r   r   r@   rA   rB   Úset_drawstylerC   r   r   r   Útest_valid_drawstyles†   s    rV   c                  C   sŒ   t  ddt j d¡} t  | ¡}t ¡ \}}| | |¡\}| d¡ t| 	¡ j
ƒdt| ƒ d ksdt‚| d¡ t| 	¡ j
ƒt| ƒksˆt‚d S )Nr   r   r2   rP   r   rO   )r	   r   ÚpiÚsinr   r-   r7   rU   ÚlenÚget_pathÚverticesr"   )r   r   r$   r%   rD   r   r   r   Útest_set_drawstyleŒ   s    

"
r\   Zline_collection_dashesZmpl20)r1   Ústylec                  C   s6   t  ¡ \} }tj d¡ |jtj dd¡dgd d S r(   r,   r/   r   r   r   Útest_set_line_coll_dash_image™   s    r^   zmarker_fill_styles.pngc                  C   sâ   t  dddgdddddt dddg¡g¡} d}t ddg¡}t dd	g¡}t ¡ \}}ttjj	ƒD ]^\}}ttjj
ƒD ]H\}}	t| ƒ}
|j|d
 | || d|d   |d||	|	d|
|
dd qvqb| ddg¡ | ddg¡ d S )Nr   r   Úgz#ff0000ÚcÚmr   Z
lightgreené	   r2   ç      à?r   r)   r3   )	ÚmarkerZ
markersizeZmarkerfacecoloraltÚ	fillstyleÚlabelZ	linewidthr;   ZmarkeredgecolorZmarkeredgewidthg      @éûÿÿÿé›   )Ú	itertoolsÚcycler	   r
   r   r-   Ú	enumerater   r   Zfilled_markersZ
fillStylesÚnextr7   Zset_ylimZset_xlim)ÚcolorsZaltcolorr   r   r$   r%   Újrd   ÚiÚfsr;   r   r   r   Útest_marker_fill_styles    s.    ÿ ÷
rq   c                  C   sD   t jdddgtddddd\} |  ¡ dks0t‚|  ¡ dks@t‚d	S )
z=Test that markerfacecolor does not override fillstyle='none'.r   r   r   Úor:   )re   Zred)rd   ZmarkerfacecolorN)r   r7   r   Zget_fillstyler"   Zget_markerfacecolor)r&   r   r   r   Útest_markerfacecolor_fillstyle¼   s
    ÿrs   Zscaled_linesrO   )r]   c            	      C   s   t  dd¡} t ¡ \}}dddg}ttjd ƒ}tt||ƒƒD ]L\}\}}t  ddd¡D ]0}|j	| |t  
d	¡ d
|  f||dœ|—Ž qXq>d S )Nr   é    rG   rJ   rH   zaxes.prop_cyclerc   r2   é2   gš™™™™™¹?r4   )r	   r   r   r-   r   Ú
matplotlibZrcParamsrk   rQ   r7   Zones)	Úthr$   r%   Zlins_stylesr   rn   rK   Zstyr6   r   r   r   Útest_lw_scalingÄ   s    
rx   c                  C   sl   t  g g ¡} |  t dddg¡¡s&t‚|  t dtjdg¡¡sBt‚|  ddgtjgd  ddg ¡rht‚d S )Nr   r   r   r3   éd   r   )r   r   Z
_is_sortedr	   r
   r"   ÚnanrC   r   r   r   Útest_nan_is_sortedÏ   s    r{   c                 C   s>   |   ¡  ddgd¡ |  ¡ jdddgdddgdddgd d S )Nr   r   z-or   ©Z	markevery)r-   Ústepr7   ©Úfig_testÚfig_refr   r   r   Útest_step_markersÖ   s    r   )Zpng)Ú
extensionsc                 C   s   t j d¡ t  ddd¡}t j t|ƒ¡}d ddddd	gdd
gtdddƒddt  t|ƒ¡|dk g	}dddddddddg	}| dd¡}|  dd¡}t	|j
|ƒD ]\}}	|j||d|	d qžt	|j
|ƒD ]4\}}	t  t|	ƒ¡ t¡ t¡}
|j||d|
d qÆd S )Né*   r   r   é   é   )r   r3   r   r3   é   éÿÿÿÿr2   r   ç333333Ó?)rˆ   gš™™™™™Ù?rc   Z11111111111111Z10001000100010Z00100001000010Z01000100000100Z10000000000001Z00000101010000Z11011011011110Z01010011011101Z01110001110110z-gDr|   )r	   r   r.   r   ZrandrY   ÚsliceZaranger-   rQ   rR   r7   r
   ÚlistZastypeÚintÚbool)r   r€   Útr   ZcasesAZcasesBZaxsAZaxsBr%   ZcaseÚmer   r   r   Útest_markeveryÜ   s2     
  þ    þr   c                  C   sì   t  ¡ \} }|jdddgtdƒd\}| j ¡  | ¡ dks@t‚| d¡ | j ¡  | tdƒ¡ | j ¡  t	ddgd	dgd
dgd
d
ggdd}|jdddgt|ƒdd\}|jdddg|dd\}t
| ¡ j|jƒ t
| ¡ j|jƒ d S )Nr   r…   r   ÚD)rd   Úsrr   g      ð¿g      ð?g        g       @T)Úclosedr   é   )rd   Úmsr   )r   r-   r7   r   r    r!   Z
get_markerr"   Z
set_markerr   r   r[   )r$   r%   rD   Z	triangle1Zline2Zline3r   r   r   Útest_marker_as_markerstyleô   s    



$r•   c                 C   sB   |   ¡ jddgdddgd |  ¡ jddgddddddgd d S )Nr   r   r   )Zdashes)Zadd_subplotr7   r~   r   r   r   Útest_odd_dashes  s    r–   c                  C   s  t  ¡ \} }t| jjd | jjd d d}|jddgddgdd\}| |¡\}}|r\t‚|jddgddgddd	\}| |¡\}}|sŽt‚t	|d
 dgƒ |jddgddgdd\}| |¡\}}|rÎt‚| 
d¡ | |¡\}}|sît‚t	|d
 dgƒ d S )Nr   é   )r   r   r   r   T)Úpickerr)   )r˜   Z
pickradiusÚind)r   r-   r   ZbboxÚwidthÚheightr7   Úcontainsr"   r   Zset_pickradius)r$   r%   Zmouse_eventZl0ÚfoundÚindicesÚl1Úl2r   r   r   Útest_picking  s$    ÿ
r¡   )0Ú__doc__ri   r   Útypesr   r   Znumpyr	   Znumpy.testingr   r@   rv   Zmatplotlib.linesÚlinesr   Zmatplotlib.markersr   Zmatplotlib.pathr   Zmatplotlib.pyplotZpyplotr   Zmatplotlib.testing.decoratorsr   r   r   ÚmarkZflakyr'   r0   r9   r>   rE   rL   rM   rT   rV   r\   r^   rq   rs   rx   r{   r   r   r•   r–   r¡   r   r   r   r   Ú<module>   sV   

+









