o
    :a                     @   s,  d dl mZ d dlZd dlZd dlZd dlZd dlmZm	Z	 d dl
Z
d dlZd dlmZ d dlmZ G dd dZG dd dZG dd	 d	ZG d
d dZG dd dZG dd dZG dd dZG dd dZG dd dZG dd dZG dd dZG dd dZG dd dZG dd dZ G d d! d!Z!G d"d# d#Z"G d$d% d%Z#G d&d' d'Z$G d(d) d)Z%G d*d+ d+Z&G d,d- d-Z'd.d/ Z(G d0d1 d1Z)d2d3 Z*d4d5 Z+d6d7 Z,d8d9 Z-d:d; Z.e
j/0d<d=d>d? Z1e
j/0d@dAdBge2dCgdDdE Z3e
j/0dFg dGej45dHdIdJ Z6dS )K    )nullcontextN)assert_almost_equalassert_array_equalc                
   @   s   e Zd Zddeg dfddeg dfddeg d	fd
dedd fdd
eddd fgZdddeg dfdddeg dfddg deg dfgZej	
dedd Zej	
dedd ZdS ) TestMaxNLocator   d   )      4@g      D@g      N@g      T@      Y@MbP?-C6?)        g-C6*?g-C6:?ga2U0*C?g-C6J?r
     4&k  4&kC)r   g  4&kr   g  4&kBr   r   g&q5   gLog5g&q   皙皙?N)r   r      ffffff?)g      пr         ?      ?      ?      ?7   )r         ?   r   
   )r         -   <   zvmin, vmax, expectedc                 C   s"   t jdd}t|||| d S )Nr   nbinsmtickerMaxNLocatorr   tick_values)selfvminvmaxexpectedloc r.   >/usr/lib/python3/dist-packages/matplotlib/tests/test_ticker.py
test_basic   s   zTestMaxNLocator.test_basiczvmin, vmax, steps, expectedc                 C   s&   t jdd|d}t|||| d S )Nr   T)r$   Zintegerstepsr%   )r)   r*   r+   r1   r,   r-   r.   r.   r/   test_integer#   s   zTestMaxNLocator.test_integer)__name__
__module____qualname__nparrayarangeZ
basic_dataZinteger_datapytestmarkparametrizer0   r2   r.   r.   r.   r/   r      s    	
r   c                   @   s   e Zd Zdd Zdd ZdS )TestLinearLocatorc                 C   0   t jdd}tg d}t|dd| d S )N   numticks)皙g333333ӿ皙?rA   rB   )r&   LinearLocatorr6   r7   r   r(   r)   r-   
test_valuer.   r.   r/   r0   *   s   zTestLinearLocator.test_basicc                 C   sB   t jdd}|jddg id |jdksJ |jdg iksJ dS )z
        Create linear locator with presets={}, numticks=2 and change it to
        something else. See if change was successful. Should not exception.
        r   r?      )r   r   )r@   presetsN)r&   rC   
set_paramsr@   rG   r)   r-   r.   r.   r/   test_set_params/   s   z!TestLinearLocator.test_set_paramsN)r3   r4   r5   r0   rJ   r.   r.   r.   r/   r<   )   s    r<   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestMultipleLocatorc                 C   r=   )NV-	@base)go"V-gV-	r   rL   V-@go"@gV-)@r   )r&   MultipleLocatorr6   r7   r   r(   rD   r.   r.   r/   r0   ;   s   zTestMultipleLocator.test_basicc                 C   R   t ddi tjdd}t|ddd W d   dS 1 s"w   Y  dS )	z5
        Test basic behavior of view limits.
        axes.autolimit_modedatarL   rM   r   r   )r   r   Nmpl
rc_contextr&   rR   r   Zview_limitsrI   r.   r.   r/   test_view_limitsA   s   "z$TestMultipleLocator.test_view_limitsc                 C   rS   )	zb
        Test that everything works properly with 'round_numbers' for auto
        limit.
        rT   Zround_numbersrL   rM      )rO   rP   NrV   rI   r.   r.   r/   test_view_limits_round_numbersI   s   "z2TestMultipleLocator.test_view_limits_round_numbersc                 C   s,   t jdd}|jdd |jjdksJ dS )z
        Create multiple locator with 0.7 base, and change it to something else.
        See if change was successful.
        ffffff?rM   g333333?N)r&   rR   rH   Z_edgestep)r)   Zmultr.   r.   r/   rJ   R   s   z#TestMultipleLocator.test_set_paramsN)r3   r4   r5   r0   rY   r\   rJ   r.   r.   r.   r/   rK   :   s
    	rK   c                	   @   s   e Zd Zdd ZddgZejdedd Zg dZ	d	d
 Z
ejde	dd Zg dZg dg dg dg dg dg dg dg dgZeeeeZejdedd ZdS )TestAutoMinorLocatorc                 C   sF   t  \}}|dd |  tg d}t|jjdd| d S )Nr   =
ףp=?皙?皙?g333333?r   g333333?gffffff??r   皙?g?r]   r   g333333??r   g?r   gffffff?g      ?g?g?Tminor)	pltsubplotsset_xlimminorticks_onr6   r7   r   xaxisget_ticklocs)r)   figaxrE   r.   r.   r/   r0   ]   s
   zTestAutoMinorLocator.test_basicr   r   )r   r   z%nb_majorticks, expected_nb_minorticksc                 C   sh   t  \}}d}|j|  |t|d |d | |  |jt	
  t|j |ks2J d S )N)r   r   r   r   )ri   rj   rk   
set_xticksr6   linspacerl   rm   set_minor_locatorr&   AutoMinorLocatorlenget_minorticklocs)r)   Znb_majorticksZexpected_nb_minorticksro   rp   xlimsr.   r.   r/   test_low_number_of_majorticksl   s   
z2TestAutoMinorLocator.test_low_number_of_majorticks))r   r   )r   r[   )      @r   )r   r   )r   r   c                 C   sX   t ddi dd | jD }tj|t j W d    d S 1 s%w   Y  d S )Nz_internal.classic_modeFc                 S   s   g | ]}|d  qS r   r.   .0xr.   r.   r/   
<listcomp>       zKTestAutoMinorLocator.test_using_all_default_major_steps.<locals>.<listcomp>)	rW   rX   majorstep_minordivisionsr6   ZtestingZassert_allcloser&   ZAutoLocatorZ_steps)r)   Z
majorstepsr.   r.   r/   "test_using_all_default_major_steps   s   "z7TestAutoMinorLocator.test_using_all_default_major_stepsz&major_step, expected_nb_minordivisionsc                 C   sb   t  \}}d|f}|j|  || |  |jt  t	|j
 d }||ks/J d S Nr   r   )ri   rj   rk   rr   rl   rm   rt   r&   ru   rv   rw   )r)   Z
major_stepZexpected_nb_minordivisionsro   rp   rx   Znb_minor_divisionsr.   r.   r/   test_number_of_minor_ticks   s   

z/TestAutoMinorLocator.test_number_of_minor_ticks))r   r`   )r   gn?)r   ԍ;)r   gVs?=)gH׊gIhG|a)gv!>ҷ>)ʔA{v()g"s2_dglEՎfUra   ){Gzt?{Gz?Q?g?gQ?gQ?g
ףp=
?rb   g)\(?gp=
ף?gQ?g333333?g(\µ?g
ףp=
?gRQ?gzG?g)\(?gq=
ףp?g      ?gp=
ף?gHzG?)gO
;gO
;gU;g#B;gU;g̈=;gnP*@;g#B;gԍ;gaW;g̈=;gmx;gJ;gnP*@;gnXen;g+3M;r   )g+<g+=gt=gvIh%=gt =g(#=gQu.U)=gvIh%,=gU.=gnb]K2=g(3=g7Q5=gU>?7=gQu.U9=gc߯x:=g; ==gU>=)g*#&,gYg#"5Ԉg_eG|gS'цgBY[%gk̈́gv!g|)vgQ؎gqrgƀg%e~gw$}g߈/|gYygv(xgS'vgv!tgz]rgqrqgw$mgHjgv(hgz]b)gL>gE/w>gZMϢ>gkʹ>g	ʧ#>g!+lěN>g:0y>gR>g};h>gBY[%>gqwNP>gʔA{>gS'Ѷ>g>g.W'>gG)R>gxz)e秷>r   )g5m/Gg<gT跾g`gxz)e秷gIGmg肸zggG)Rg<g&|gg5_涾gqdqAg34gY#)g#"5Ըg_~r   gҷg.W'gS'Ѷr   gBY[%g:0yg	ʧ#gkʹgE/wgE̳g|)vg<sAC gz]ʲgQ؎g 4PSȱgqrg>g\+-eqg+i)+gM7܉g%eޮgw$zlim, refc                 C   sZ   t  \}}|  |jddddd |jddddd || t|jjdd	| d S )
NTrh   yr   )	linewidthmajork)Zcolorr   rg   )ri   rj   rl   Zgridset_ylimr   yaxisrn   )r)   limrefro   rp   r.   r.   r/   test_additional   s   
z$TestAutoMinorLocator.test_additionalN)r3   r4   r5   r0   paramsr9   r:   r;   ry   r   r   r   ZlimitsZ	referencelistzipZadditional_datar   r.   r.   r.   r/   r_   \   s4    

r_   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestLogLocatorc                 C   s   t jdd}tt |dd W d    n1 sw   Y  tg d}t|dd| t jdd	}tg d
}t|dd| d S )Nr   r?   r     )h㈵>r
   rc         $@     @@     j@g    cA    eAr
   g     @r   rM   )
r   r          @      @g       @g      0@g      @@g      P@g      `@g      p@r   r   )	r&   
LogLocatorr9   raises
ValueErrorr(   r6   r7   r   rD   r.   r.   r/   r0      s   zTestLogLocator.test_basicc                 C   sb   t jdd}t|ddg d t jtddd}d|d	d
vs%J d|d	d
vs/J d S )Nallsubsrd   re   )g)\(?gq=
ףp?gQ?r   gp=
ף?gHzG?gQ?r   r   r   rf   r   r   )r&   r   r   r(   r6   r8   rI   r.   r.   r/   test_switch_to_autolocator   s   z)TestLogLocator.test_switch_to_autolocatorc                 C   s^   t  }|jdddgdd |jdksJ |jdksJ |jdks#J t|jdgks-J dS )z
        Create log locator with default value, base=10.0, subs=[1.0],
        numdecs=4, numticks=15 and change it to something else.
        See if change was successful. Should not raise exception.
           rF   r   r[   )r@   numdecsr   rN   N)r&   r   rH   r@   r   _baser   _subsrI   r.   r.   r/   rJ      s   zTestLogLocator.test_set_paramsN)r3   r4   r5   r0   r   rJ   r.   r.   r.   r/   r      s    	r   c                   @      e Zd Zdd ZdS )TestNullLocatorc                 C   s@   t  }tt |  W d   dS 1 sw   Y  dS )z
        Create null locator, and attempt to call set_params() on it.
        Should not exception, and should raise a warning.
        N)r&   ZNullLocatorr9   warnsUserWarningrH   rI   r.   r.   r/   rJ      s   
"zTestNullLocator.test_set_paramsNr3   r4   r5   rJ   r.   r.   r.   r/   r          r   c                   @   s$   e Zd Zedd Zedd ZdS )_LogitHelperc                 C   s`   d|   k r
dk r.n n"d|  k rdk r.n nt t d|  d  t d| d  S dS )Nr   r   F)r6   iscloselog)r~   r   r.   r.   r/   r      s   
6z_LogitHelper.isclosec                 C   s   t | }t |}t |dkrt |dk sJ t |dkr(t |dk s*J t d| d  }t d| d  }t|| d S r   )r6   r7   r   r   r   )r~   r   rp   ZayZlxZlyr.   r.   r/   r      s   

  z _LogitHelper.assert_almost_equalN)r3   r4   r5   staticmethodr   r   r.   r.   r.   r/   r      s
    
r   c                   @   s  e Zd Zg dZddedd  ddedd  ddedd  ddedd  ddedd  ddedd	  ddedd
  ddedd  gZg dZej	
deeedd Zej	
dedd Zej	
dee dd Zej	
deeedd Zdd Zg dedd ddedd  Zej	
ddd ejeddD dd  Zej	
d!ed"d# Zd$S )%TestLogitLocator)rb   r   )r   gףp=
?)gMb@?gCl?-C6
?gSt$?)gh㈵>g;?)gƠ>g?gHj>ge(?)g:0y5>g$P?r   r   r>   r[   r   r   r   rF   	   ))g?g333333?)rb   rB   )g?r   zlims, expected_low_ticksc                 C   s:   t g |dd| }tjdd}t|j| | dS )zR
        Create logit locator with huge number of major, and tests ticks.
        r   r   r   r#   N)sortedr&   LogitLocatorr   r   r(   )r)   limsexpected_low_ticksexpected_ticksr-   r.   r.   r/   test_basic_major  s   z!TestLogitLocator.test_basic_majorr   c                 C   sx   t jdd}t jdg dd}dD ](}|j|d |j|d |j| }|j| }|j|jks1J ||k s9J qdS )zj
        When the axis is zoomed, the locator must have the same behavior as
        MaxNLocator.
        r   r#   )r   r   r   r   )r$   r1   )r[   rF      N)r&   r   r'   rH   r(   shaper   )r)   r   r-   Zmaxn_locr$   ticksZ
maxn_ticksr.   r.   r/   test_maxn_major/  s   

z TestLogitLocator.test_maxn_majorc                 C   sj   t tt|d  d d }tjdd}t|ddD ]}|j|d t|j	| |d ks2J qdS )zB
        Assert logit locator for respecting nbins param.
        r   r   r   r   r#   r   N)
intr6   floorlog10r&   r   rangerH   rv   r(   )r)   r   basic_neededr-   r$   r.   r.   r/   test_nbins_major?  s   "z!TestLogitLocator.test_nbins_majorc           
      C   s   t g |dd| }t|}tjdd}tjddd}t|ddD ];}|j|d |j|d |j| }|j| }	t|t|krRt|d d	 t|	k sQJ q#tt g ||	| q#d
S )zt
        In large scale, test the presence of minor,
        and assert no minor when major are subsampled.
        r   r   r   r#   T)r$   rh   r   r   r   N)	r   rv   r&   r   r   rH   r(   r   r   )
r)   r   r   r   r   r-   Z	minor_locr$   Zmajor_ticksZminor_ticksr.   r.   r/   
test_minorK  s"   


zTestLogitLocator.test_minorc                 C   s@   t jdd}|jrJ d|_|jsJ |jdd |jrJ d S )Nr   r#   TFrg   )r&   r   rh   rH   rI   r.   r.   r/   test_minor_attrh  s   

z TestLogitLocator.test_minor_attrrz   r   c                 C   s    g | ]\}}||kr||fqS r.   r.   )r}   abr.   r.   r/   r   w  s    zTestLogitLocator.<listcomp>r   )repeatc                 C   s*   t  }|j| }t|t|ksJ dS )zd
        Create logit locator, and test the nonsingular method for acceptable
        value
        N)r&   r   nonsingularr   )r)   r   r-   Zlims2r.   r.   r/   test_nonsingular_oku  s   
z$TestLogitLocator.test_nonsingular_okokvalc                 C   s   t  }d|}}|||\}}||ksJ d|  k r"|k s%J  J |d}}|||\}}||ks8J ||  k rCdk sFJ  J dS )zh
        Create logit locator, and test the nonsingular method for non
        acceptable value
        r   r   r   r   N)r&   r   r   )r)   r   r-   r*   r+   Zvmin2Zvmax2r.   r.   r/   test_nonsingular_nok  s   

 z%TestLogitLocator.test_nonsingular_nokN)r3   r4   r5   Zref_basic_limitsr6   r8   Zref_basic_major_ticksZref_maxn_limitsr9   r:   r;   r   r   r   r   r   r   Zacceptable_vmin_vmax	itertoolsproductr   r   r.   r.   r.   r/   r     sR    




	r   c                   @   r   )TestFixedLocatorc                 C   s2   t jtdddd}|jdd |jdksJ dS )z
        Create fixed locator with 5 nbins, and change it to something else.
        See if change was successful.
        Should not exception.
        r      r   r#   r   N)r&   ZFixedLocatorr   rH   r$   )r)   fixedr.   r.   r/   rJ     s   z TestFixedLocator.test_set_paramsNr   r.   r.   r.   r/   r     r   r   c                   @   r   )TestIndexLocatorc                 C   s<   t jddd}|jddd |jdksJ |jdksJ dS )z
        Create index locator with 3 base, 4 offset. and change it to something
        else. See if change was successful.
        Should not exception.
        r>   r[   )rN   offsetr   N)r&   ZIndexLocatorrH   r   r   )r)   indexr.   r.   r/   rJ     s   z TestIndexLocator.test_set_paramsNr   r.   r.   r.   r/   r     r   r   c                   @   r   )TestSymmetricalLogLocatorc                 C   s@   t jddd}|jdgdd |jdgksJ |jdksJ dS )z
        Create symmetrical log locator with default subs =[1.0] numticks = 15,
        and change it to something else.
        See if change was successful.
        Should not exception.
        r   r   )rN   Z	linthreshr   rF   )r   r@   N)r&   ZSymmetricalLogLocatorrH   r   r@   )r)   Zsymr.   r.   r/   rJ     s   z)TestSymmetricalLogLocator.test_set_paramsNr   r.   r.   r.   r/   r     r   r   c                   @   s   e Zd Zg dZddgZg dZddgddgd	d
gddgddggZej	dddgdd Z
ej	dedd Zej	dedd Zdd Zej	dedd Zej	ded d! Zej	ded"d# Zd$d% Zd&S )'TestScalarFormatter)){      r   )iCir   )i50  i=0  i40  )iii)g    i@g    j@順 )g    jg    i`y)g    hi@g    j@r   )g    jg    hir   )iO iQ iP )i+i+i+)r   r   r   )r   r   r   )g/'?g_L?rd   )g
ףp=@g33333@i  )g@g    `@iȯ  )g1е/G?gg޻G?g9̗G?)g\h@gp=
@i.1  )g      "@g      (@r   )g      @     @r   )g     @r   r   )Gz?g)\(?r   )g{G#@gQ$@r   )g(\X@gq=
ף Y@r   )g(\@g
ףp=
@r   )g{G/@g(\0@r   )g!rhܿrh|?r   )grh|߿r   r   )g3333@g    @@i0  )gffffgffff@r   TF)	)Frq   )r   r   r   F)Tr   )ir   r   F)Tr   )ir   r   F)Tr   )ix   r   F)Tr   )in   r   F)Tr   )gMbPgMb`?r   F)T)rQ   r   )g   tAg   0Ar   T)Trq   g     jr   r   F)T)r   r   r   r   Fr   z0.000g(0?z0.012grh|?z0.123gGz?z1.230g(@z12.300zunicode_minus, result)T   −1)F-1c                 C   s.   |t jd< t j d |ksJ d S )Naxes.unicode_minusr   )rW   rcParamsri   Zgcarm   get_major_formatterformat_data_shortstrip)r)   unicode_minusresultr.   r.   r/   test_unicode_minus  s
   

z&TestScalarFormatter.test_unicode_minuszleft, right, offsetc                 C   s   t  \}}|j }||krtjtddnt  ||| W d    n1 s*w   Y  |j	  |j
|ks;J ||krFtjtddnt  ||| W d    n1 sZw   Y  |j	  |j
|kskJ d S )NzAttempting to set identicalmatch)ri   rj   rm   r   r9   r   r   r   rk   Z_update_ticksr   )r)   leftrightr   ro   rp   	formatterr.   r.   r/   test_offset_value  s$   


z%TestScalarFormatter.test_offset_value
use_offsetc                 C   sL   t d|i t }|| ksJ W d    d S 1 sw   Y  d S )Nzaxes.formatter.useoffset)rW   rX   r&   ScalarFormatterZget_useOffset)r)   r   tmp_formr.   r.   r/   test_use_offset  s   "z#TestScalarFormatter.test_use_offsetc                 C   s   t  }|d }|r|d dd  g t jgfv rtd tddi- t }|	 s/J |
  |jdd |g d	 ||d
v sIJ W d    d S 1 sTw   Y  d S )Nthousands_sepgroupingr   zLocale does not apply groupingzaxes.formatter.use_localeTr   r   )r   r   r>   r   )locale
localeconvCHAR_MAXr9   skiprW   rX   r&   r   Zget_useLocalecreate_dummy_axisaxisZset_data_intervalset_locs)r)   convsepr   r.   r.   r/   test_use_locale  s    
"z#TestScalarFormatter.test_use_localez.sci_type, scilimits, lim, orderOfMag, fewticksc           	      C   sv   t  }|| || t \}}|j| |j|  |r*|j	t 
d ||j  ||jks9J d S )Nr[   )r&   r   Zset_scientificZset_powerlimitsri   rj   r   set_major_formatterr   set_major_locatorr'   r  get_majorticklocsZorderOfMagnitude)	r)   Zsci_typeZ	scilimitsr   Z
orderOfMagZfewticksr   ro   rp   r.   r.   r/   test_scilimits%  s   


z"TestScalarFormatter.test_scilimitszdata, expectedc                 C   s8   t  \}}|dd |j j}|||ksJ d S )Nr   r   )ri   rj   rk   rm   r   r   )r)   rU   r,   ro   rp   fmtr.   r.   r/   test_cursor_precision4  s   z)TestScalarFormatter.test_cursor_precisionc                 C   s8   t  }|  |jdd |j}|||ksJ d S )Nr   r   )r&   r   r  r  Zset_view_intervalr   )r)   rU   r,   Zsfr  r.   r.   r/   test_cursor_dummy_axis;  s
   z*TestScalarFormatter.test_cursor_dummy_axisc                 C   sl   t jdddd tjtdd t \}}|g d |j	
  W d    d S 1 s/w   Y  d S )NZserifZcmr10F)zfont.familyz
font.serifzaxes.formatter.use_mathtextzcmr10 font should ideallyr   )r   r   r   )rW   r   updater9   r   r   ri   rj   rr   canvasdraw)r)   ro   rp   r.   r.   r/   test_mathtext_ticksD  s   "z'TestScalarFormatter.test_mathtext_ticksN)r3   r4   r5   Zoffset_dataZuse_offset_dataZscilimits_dataZcursor_datar9   r:   r;   r   r   r   r  r  r  r  r  r.   r.   r.   r/   r     s8    !





r   c                   @   s"   e Zd ZdZd	ddZdd ZdS )
FakeAxiszAAllow Formatter to be called without having a "full" plot set up.r   r   c                 C   s   || _ || _d S Nr*   r+   )r)   r*   r+   r.   r.   r/   __init__S  s   
zFakeAxis.__init__c                 C   s   | j | jfS r  r  )r)   r.   r.   r/   get_view_intervalW  s   zFakeAxis.get_view_intervalNr   r   )r3   r4   r5   __doc__r  r  r.   r.   r.   r/   r  Q  s    
r  c                   @   s   e Zd Zddeddeddg dfddedd	ejd
ddgedg dfddejg dededg dfgZ	dddejej
gZejde	ejdedd Zdd ZdS )TestLogFormatterExponentTr[   r   r   )z-3z-2r   0123Fr   rc   r   rB   gɿgh㈵r   )0.1z1e-053.14z0.2z-0.2z-1e-052   )r>   r      *   Zdtype)r"  5Z12Z42r   g      @r   z2labelOnlyBase, exponent, locs, positions, expectedrN   c           	         sN   t j||d td||  _|| } fddt||D }||ks%J d S )NrN   labelOnlyBaser   c                    s   g | ]	\}} ||qS r.   r.   )r}   r~   posr   r.   r/   r   r      z7TestLogFormatterExponent.test_basic.<locals>.<listcomp>)r&   LogFormatterExponentr  r  r   )	r)   r+  rN   ZexponentlocsZ	positionsr,   Zvalslabelsr.   r-  r/   r0   i  s   z#TestLogFormatterExponent.test_basicc                 C   s*   t jddd}t |_|ddksJ d S )Nr   Tr*  g&$? )r&   r/  r  r  )r)   r   r.   r.   r/   
test_blanku  s   z#TestLogFormatterExponent.test_blankN)r3   r4   r5   r6   r8   r7   Zpir   floatZ
param_dataeZ	base_datar9   r:   r;   r0   r3  r.   r.   r.   r/   r  [  s$    	r  c                   @   s2   e Zd Ze Zg dZej	dedd Z
dS )TestLogFormatterMathtext))r   r   $\mathdefault{10^{0}}$)r   r   z$\mathdefault{10^{-2}}$)r   r	   z$\mathdefault{10^{2}}$)r>   r   z$\mathdefault{1}$)r>   r   z$\mathdefault{0.01}$)r>   r	   z$\mathdefault{100}$)r>   r
   z$\mathdefault{10^{-3}}$)r>   r   z$\mathdefault{10^{3}}$zmin_exponent, value, expectedc                 C   sF   t d|i | ||ksJ W d    d S 1 sw   Y  d S )Nzaxes.formatter.min_exponent)rW   rX   r  )r)   Zmin_exponentvaluer,   r.   r.   r/   test_min_exponent  s   "z*TestLogFormatterMathtext.test_min_exponentN)r3   r4   r5   r&   ZLogFormatterMathtextr  	test_datar9   r:   r;   r9  r.   r.   r.   r/   r6  |  s
    r6  c                   @   s6   e Zd Zg dZejdej	dedd Z
dS )TestLogFormatterSciNotation))r   g      ?z$\mathdefault{2^{-5}}$)r   r   z$\mathdefault{2^{0}}$)r       z$\mathdefault{2^{5}}$)r   g333333?z$\mathdefault{1.2\times2^{-5}}$)r   333333?z$\mathdefault{1.2\times2^{0}}$)r   g333333C@z$\mathdefault{1.2\times2^{5}}$)r   r   z$\mathdefault{-10^{0}}$)r   r   z$\mathdefault{10^{-5}}$)r   r   r7  )r   r   z$\mathdefault{10^{5}}$)r   gh㈵>z$\mathdefault{2\times10^{-5}}$)r   r   z$\mathdefault{2\times10^{0}}$)r   i@ z$\mathdefault{2\times10^{5}}$)r   r   z$\mathdefault{5\times10^{-5}}$)r   r   z$\mathdefault{5\times10^{0}}$)r   i  z$\mathdefault{5\times10^{5}}$defaultzbase, value, expectedc                 C   sZ   t j|d}h d|_tddi |||ksJ W d    d S 1 s&w   Y  d S )NrM   >   r=  r   r   r   text.usetexF)r&   ZLogFormatterSciNotationZsublabelrW   rX   )r)   rN   r8  r,   r   r.   r.   r/   r0     s
   
"z&TestLogFormatterSciNotation.test_basicN)r3   r4   r5   r:  rW   stylecontextr9   r:   r;   r0   r.   r.   r.   r/   r;    s
    
r;  c                   @   s|   e Zd Zg dZejdedd ZdddZe	j
dd	d
 Zejdg ddd Zejdg ddd ZdS )TestLogFormatter))}9x ?r
   z3.142e-5)Gŷ4?r
   z3.142e-4)ei?r
   z3.142e-3)\, ?r
   z3.142e-2)s7v/?r
   z3.142e-1)PERT!	@r
   3.142)f)zj?@r
   z3.142e1)&FYs@r
   z3.142e2)WXp/@r
   z3.142e3)mnL@r
   z3.142e4),Ar
   z3.142e5)r   r
   1e-5)r   r
   1e-4)r
   r
   1e-3)r   r
   1e-2)rc   r
   1e-1)r   r
   r   )r   r
   10)r   r
   100)r   r
   1000)'  r
   1e4)r   r
   1e5)rC  r   r  )rD  r   r  )rE  r   0.003)rF  r   0.031)rG  r   0.314)rH  r   rI  )rJ  r   31.416)rK  r   314.159)rL  r   3141.593)rM  r   	31415.927)rN  r   
314159.265)r   r   r  )r   r   r  )r
   r   0.001)r   r   0.01)rc   r   r#  )r   r   r   )r   r   rT  )r   r   rU  )r   r   rV  )rW  r   10000)r   r   100000)rC  r   r  )rD  r   r  )rE  r   rZ  )rF  r   r[  )rG  r   r\  )rH  r   rI  )rJ  r   r]  )rK  r   r^  )rL  r   r_  )rM  r   r`  )rN  r   ra  )r   r   r  )r   r   r  )r
   r   rb  )r   r   rc  )rc   r   r#  )r   r   r   )r   r   rT  )r   r   rU  )r   r   rV  )rW  r   rd  )r   r   re  )rC  r   r  )rD  r   r  )rE  r   r  )rF  r   z0.03)rG  r   z0.31)rH  r   r$  )rJ  r   z31.42)rK  r   z314.16)rL  r   z3141.59)rM  r   z31415.93)rN  r   z	314159.27)r   r   r  )r   r   r  )r
   r   r  )r   r   rc  )rc   r   r#  )r   r   r   )r   r   rT  )r   r   rU  )r   r   rV  )rW  r   rd  )r   r   re  )rC  r   r  )rD  r   r  )rE  r   r  )rF  r   r  )rG  r   z0.3)rH  r   3.1)rJ  r   z31.4)rK  r   z314.2)rL  r   z3141.6)rM  r   z31415.9)rN  r   z314159.3)r   r   r  )r   r   r  )r
   r   r  )r   r   r  )rc   r   r#  )r   r   r   )r   r   rT  )r   r   rU  )r   r   rV  )rW  r   rd  )r   r   re  )rC      .Az3.1e-5)rD  rg  z3.1e-4)rE  rg  z3.1e-3)rF  rg  z3.1e-2)rG  rg  z3.1e-1)rH  rg  rf  )rJ  rg  z3.1e1)rK  rg  z3.1e2)rL  rg  z3.1e3)rM  rg  z3.1e4)rN  rg  z3.1e5)r   rg  rO  )r   rg  rP  )r
   rg  rQ  )r   rg  rR  )rc   rg  rS  )r   rg  r   )r   rg  rT  )r   rg  rU  )r   rg  rV  )rW  rg  rX  )r   rg  rY  zvalue, domain, expectedc                 C   s$   t  }|||}||ksJ d S r  )r&   LogFormatterZ_pprint_val)r)   r8  domainr,   r  Zlabelr.   r.   r/   test_pprint4  s   zTestLogFormatter.test_pprintr.   c                    sf   |   | } | |dtt|  }fdd|D } fdd|D }||ks1J dS )z.Test whether locator marks subs to be labeled.r   c                    s   g | ]}t | v qS r.   )round)r}   cr   r.   r/   r   @      z0TestLogFormatter._sub_labels.<locals>.<listcomp>c                       g | ]} |d kqS r2  r.   r|   r  r.   r/   r   A  rm  N)Zget_minor_formatterrw   r  r6   r   r   )r)   r  r   Zminor_tlocsZcoefsZlabel_expectedZ
label_testr.   )r  r   r/   _sub_labels:  s   
zTestLogFormatter._sub_labelsr>  c                    sR  t  \}}|d |jtjdg d |jtjdt	ddd |j
tjdd |jtjdd |dd	 |j   |j   fd
d|j D }t|s_J | j|jg d |dd | j|jg d |dd | j|jg d |dd | j|jg dd |dd | j|jtj	ddtdd d S )Nr   r   )rN   r   r   T)r+  Fr   g     @c                    rn  ro  r.   r|   rp  r.   r/   r   R  s    z2TestLogFormatter.test_sublabel.<locals>.<listcomp>r   i   P   rF   )r   r>   r[   r   r   rf   r(  )ri   rj   Z
set_xscalerm   r  r&   r   rt   r6   r8   r  rh  set_minor_formatterrk   r   r  r  r   rq  r   )r)   ro   rp   Zshow_major_labelsr.   rp  r/   test_sublabelD  s0   



 zTestLogFormatter.test_sublabelval)r   r   r   r   c                 C   s(   t  }t |_||t|ksJ d S r  )r&   rh  r  r  strr)   ru  Ztemp_lfr.   r.   r/   test_LogFormatter_callj  s   z'TestLogFormatter.test_LogFormatter_call)g       g       g       g       c                 C   s   t  }t |_|| d S r  )r&   rh  r  r  rw  r.   r.   r/   test_LogFormatter_call_tinyq  s   z,TestLogFormatter.test_LogFormatter_call_tinyN)r.   )r3   r4   r5   Zpprint_datar9   r:   r;   rj  rq  rW   r@  rA  rt  rx  ry  r.   r.   r.   r/   rB    s     




%
rB  c                   @   s  e Zd Zedd Zejdg ddd Ze	dd e
d	d
D dd e
d	d
D  dg Zejdedd Zejdddd Zejdd	d	eeddd
   dd Zg dZejdedd Zdd Zdd Zdd  Zejd!d"d#d$ Zd%S )&TestLogitFormatterc                 C   s   t d| }|r@|d du}|d rt|d nd}|d dur&t|d nd}|d|  }|d s8|d dur@|r>d| S |S t d	| }|rYt|d
 t|d }}|| S td)z
        Parser to convert string as r'$\mathdefault{1.41\cdot10^{-4}}$' in
        float 1.41e-4, as '0.5' or as r'$\mathdefault{\frac{1}{2}}$' in float
        0.5,
        zT[^\d]*(?P<comp>1-)?(?P<mant>\d*\.?\d*)?(?:\\cdot)?(?:10\^\{(?P<expo>-?\d*)})?[^\d]*$compNZmantr   expor   r   z4[^\d]*\\frac\{(?P<num>\d+)\}\{(?P<deno>\d+)\}[^\d]*$numdenozNot formatted by LogitFormatter)rer   r4  r   r   )stringr   r{  Zmantissar|  r8  r}  r~  r.   r.   r/   logit_deformatterz  s(   	z$TestLogitFormatter.logit_deformatterzfx, x))zSTUFF0.41OTHERSTUFFg=
ףp=?)zSTUFF1.41\cdot10^{-2}OTHERSTUFFg!u?)zSTUFF1-0.41OTHERSTUFFgzG?)z!STUFF1-1.41\cdot10^{-2}OTHERSTUFFgx$(~?)ZSTUFFN)zSTUFF12.4e-3OTHERSTUFFNc                 C   s`   |d u r!t t t| W d    d S 1 sw   Y  d S t|}t||s.J d S r  )r9   r   r   rz  r  r   r   )r)   fxr~   r   r.   r.   r/   test_logit_deformater  s   "
z(TestLogitFormatter.test_logit_deformaterc                 C   s   g | ]}d |  qS )r   r.   r}   ir.   r.   r/   r     s    zTestLogitFormatter.<listcomp>r   r   c                 C   s   g | ]	}d d|   qS r  r.   r  r.   r.   r/   r     r.  r   r~   c                 C   s>   t jdd}|| j ||}t|}t||sJ dS )zj
        Test the formatted value correspond to the value for ideal ticks in
        logit space.
        Fuse_overlineN)r&   LogitFormatterr  decade_testrz  r  r   r   )r)   r~   r   sx2r.   r.   r/   r0     s
   
zTestLogitFormatter.test_basic)r   g      r   r   r   r   c                 C   s0   t jdd}|| j ||}|dksJ dS )zl
        Test that invalid value are formatted with empty string without
        raising exception.
        Fr  r2  N)r&   r  r  r  )r)   r~   r   r  r.   r.   r/   test_invalid  s   zTestLogitFormatter.test_invalidrQ   r   c                 C   s   t jdd}dD ]@}|d|  dk rH||d|  ||d|  g ||}||d|  }t|t| }d|  k rEd| k sHJ  J qdS )zS
        The format length should change depending on the neighbor labels.
        Fr  )	r   r   r%  r      r   i  i  rW  r   r   r   N)r&   r  r  rz  r  )r)   r~   r   NZsxZsx1dr.   r.   r/   test_variablelength  s     z&TestLogitFormatter.test_variablelength))Tr   )   F)K   F)Tr   )r  r  T)Tr   )r  Tr  )F)r   gRQ?gp=
ף?))r   Tr  r  zmethod, lims, casesc                 C   s   |rt jdd}|j| }nt|}t jdd}|D ]0\}}|| ||}	dd |	D }
|r?t|
dks>J ||fqt|
dksKJ ||fqdS )z,
        Test minor/major displays.
        Trg   c                 S      g | ]
}t |d kr|qS r{   rv   r}   fr.   r.   r/   r         z:TestLogitFormatter.test_minor_vs_major.<locals>.<listcomp>r   N)	r&   r   r(   r6   r7   r  Zset_minor_thresholdformat_ticksrv   )r)   methodr   casesmin_locr   min_formZ	thresholdZ	has_minor	formattedlabelledr.   r.   r/   test_minor_vs_major  s   


z&TestLogitFormatter.test_minor_vs_majorc                 C   sd   t jdd}t jdd}|dd}dD ]}|| ||}dd |D }t||ks/J qdS )	z1
        Test the parameter minor_number
        Trg   rb   r   )r   r[   rF   r   c                 S   r  r{   r  r  r.   r.   r/   r     r  z8TestLogitFormatter.test_minor_number.<locals>.<listcomp>N)r&   r   r  r(   Zset_minor_numberr  rv   )r)   r  r  r   Zminor_numberr  r  r.   r.   r/   test_minor_number  s   

z$TestLogitFormatter.test_minor_numberc                 C   s`   d}d}d}t jdd}|||ksJ |d |||ks!J |d |||ks.J dS )z1
        Test the parameter use_overline
        r   z$\mathdefault{1-10^{-2}}$z"$\mathdefault{\overline{10^{-2}}}$Fr  TN)r&   r  r  )r)   r~   Zfx1Zfx2formr.   r.   r/   test_use_overline  s   

z$TestLogitFormatter.test_use_overlinec                 C   sP   t  }d|dv sJ |d d|dv sJ |d d|dv s&J dS )z-
        Test the parameter one_half
        z\frac{1}{2}r   z1/2zone halfN)r&   r  Zset_one_half)r)   r  r.   r.   r/   test_one_half  s   

z TestLogitFormatter.test_one_halfr  )r      i  c                 C   sv   t dd|dd }t }|D ]'}||}|dr(dt|dd   }nt|}t|| d| k s8J qd S )Nr   r   r   z1-r   )r6   rs   r&   r  r   
startswithr4  abs)r)   r  r0  r  r~   r  r  r.   r.   r/   test_format_data_short  s   

z)TestLogitFormatter.test_format_data_shortN)r3   r4   r5   r   r  r9   r:   r;   r  r   r   r  r0   r  r6   Zexprs   r  Zlims_minor_majorr  r  r  r  r  r.   r.   r.   r/   rz  y  s:    
 


&


rz  c                   @   r   )TestFormatStrFormatterc                 C   s   t d}d|dksJ d S )Nz%05d00002r   )r&   ZFormatStrFormatter)r)   r   r.   r.   r/   r0   ,     
z!TestFormatStrFormatter.test_basicN)r3   r4   r5   r0   r.   r.   r.   r/   r  +  r   r  c                   @   s*   e Zd ZddgZejdedd ZdS )TestStrMethodFormatter)z{x:05d})r   r  )z{x:03d}-{pos:02d})r   r   z002-01zformat, input, expectedc                 C   s   t |}|| |ksJ d S r  )r&   ZStrMethodFormatter)r)   formatinputr,   r  r.   r.   r/   r0   8  r  z!TestStrMethodFormatter.test_basicN)r3   r4   r5   r:  r9   r:   r;   r0   r.   r.   r.   r/   r  2  s    r  c                   @   s*   e Zd Zg dZejdedd ZdS )TestEngFormatter))FEJ)z
-1.23457 k-1 kz-1.23 k)Tr  )u   −1.23457 k   −1 ku	   −1.23 k)FރB)z-1.23457r   z-1.23)Tr  )u
   −1.23457r   u   −1.23)F_c97ݚ)z
-123.457 mz-123 mz	-123.46 m)Tr  )u   −123.457 mu   −123 mu   −123.46 m)FQ^-':T)z
-1.23457 mz-1 mz-1.23 m)Tr  )u   −1.23457 mu   −1 mu	   −1.23 m)Tg       r  r  z0.00Tr   r  r  )Tgm>)u
   1.23457 µu   1 µu   1.23 µ)Tg_c97ݚ?)z	123.457 mz123 mz123.46 m)Trc   )100 mr  z100.00 m)Tr   )r   r   z1.00)TgރB?)z1.23457r   z1.23)Tg33333?@)z999.91 kz999.90)Tg*:?@r  r  1.00 k)F*:?)r  r  z-1.00 k)Tr  )r  r  u	   −1.00 k)Tr   r  )Ti  )z1.001 kr  r  )Ti )z	100.001 kz100 kz100.00 k)TgZ$.A)z	987.654 kz988 kz987.65 k)TguˏE)1230 Yr  z	1230.00 Yzunicode_minus, input, expectedc                    s  |t jd< dd |}t tjddtjddf}t||D ]\}}|||ks+J q fdd|D }tjd	tjdd
tjdd
f}t||D ]\}}|||ksZJ qNdD ]c fdd|D }tjdtjddtjddf}t||D ]\}}|||ksJ qfdd|D }tjdtjddtjddf}t||D ]\}}|||ksJ qq]dS )a  
        Test the formatting of EngFormatter for various values of the 'places'
        argument, in several cases:

        0. without a unit symbol but with a (default) space separator;
        1. with both a unit symbol and a (default) space separator;
        2. with both a unit symbol and some non default separators;
        3. without a unit symbol but with some non default separators.

        Note that cases 2. and 3. are looped over several separator strings.
        r   r  
0123456789r   )placesr   c                 3   s0    | ]}|d   v r|d  n| V  qdS r    Nr.   r}   Z_s)DIGITSUNITr.   r/   	<genexpr>  s    
z/TestEngFormatter.test_params.<locals>.<genexpr>)unit)r  r  )r2  u    z@_@c                 3   s8    | ]}|d   v r|  n| d V  qdS r  replacer  r  r  _sepr.   r/   r    s    
)r  r
  )r  r  r
  c                 3   s    | ]	}| d  V  qdS )r  Nr  r  )r  r.   r/   r    s    )r
  )r  r
  N)ri   r   r&   EngFormatterr   )r)   r   r  r,   Zexp_outputsZ
formattersZ
_formatterZ_exp_outputr.   r  r/   test_paramsg  sL   




zTestEngFormatter.test_paramsN)r3   r4   r5   Zraw_format_datar9   r:   r;   r  r.   r.   r.   r/   r  >  s    %r  c                  C   s   t  \} }|g dg d |g d tjddtjddfD ]}|j| | j	  dd |
 D }|g dksAJ q#d S )N)r   i  r   T)usetex)ZuseMathTextc                 S   s   g | ]}|  qS r.   )Zget_text)r}   Zlablr.   r.   r/   r     r   z8test_engformatter_usetex_useMathText.<locals>.<listcomp>)z$0$z$500$z$1$ k)ri   rj   plotrr   r&   r  rm   r  r  r  Zget_xticklabels)ro   rp   r   Zx_tick_label_textr.   r.   r/   $test_engformatter_usetex_useMathText  s   


r  c                   @   sT   e Zd Zg dZg dZg dZejjdeeddd Z	ejded	d
 Z
dS )TestPercentFormatter))r   r   %r   r   z120%)r   r   r  r   Z   z100%)r   r   r  r  r%  z90%)r   r   r  g333333(   z-2%)r   r   r  g     V@r   z90.0%)r   r   r  gfffffT@r  z80.1%)r   r   r  gQQ@r%  z70.2%)r   r   r  gxFNr  z-60.6%)r   Nr  _   r   z95.00%)r   Nr  r>   r   z300%)      1@Nr  r   g      !@z6%)r  Nr  r   g @z5.9%)r   Nr  igư>z-2000.00000%)r   r   Nr=  r   z120.00)r  r>   r2  r%  r   z66.667)r'  Nz
^^Foobar$$   r&  z50.0^^Foobar$$)zdecimals=0, x>100%zdecimals=0, x=100%zdecimals=0, x<100%zdecimals=0, x<0%zdecimals=1, x>100%zdecimals=1, x=100%zdecimals=1, x<100%zdecimals=1, x<0%z$autodecimal, x<100%, display_range=1z7autodecimal, x>100%, display_range=6 (custom xmax test)z;autodecimal, x<100%, display_range=8.5 (autodecimal test 1)z;autodecimal, x<100%, display_range=8.4 (autodecimal test 2)z=autodecimal, x<-100%, display_range=1e-6 (tiny display range)zNone as percent symbolzEmpty percent symbolzCustom percent symbol))FF50\{t}%)FTz50\\\{t\}\%)TFr  )TTr  z2xmax, decimals, symbol, x, display_range, expected)Zidsc                 C   sX   t |||}tjddid ||||ksJ W d    d S 1 s%w   Y  d S )Nr?  Frcr&   ZPercentFormatterrW   rX   Z
format_pct)r)   ZxmaxZdecimalssymbolr~   Zdisplay_ranger,   r   r.   r.   r/   r0     s   "zTestPercentFormatter.test_basiczis_latex, usetex, expectedc                 C   sX   t jd|d}tjd|id |dd|ksJ W d    d S 1 s%w   Y  d S )Nz\{t}%)r  is_latexr?  r  r%  r   r  )r)   r  r  r,   r  r.   r.   r/   
test_latex  s   "zTestPercentFormatter.test_latexN)r3   r4   r5   Zpercent_dataZpercent_idsZ
latex_datar9   r:   r;   r0   r  r.   r.   r.   r/   r    s    
r  c                  C   L   t  \} }tt |jt  W d    d S 1 sw   Y  d S r  )	ri   rj   r9   r   	TypeErrorrm   r  r&   r   ro   rp   r.   r.   r/   test_majformatter_type     "r  c                  C   r  r  )	ri   rj   r9   r   r  rm   rs  r&   r   r  r.   r.   r/   test_minformatter_type  r  r  c                  C   r  r  )	ri   rj   r9   r   r  rm   r  r&   rh  r  r.   r.   r/   test_majlocator_type  r  r  c                  C   r  r  )	ri   rj   r9   r   r  rm   rt   r&   rh  r  r.   r.   r/   test_minlocator_type  r  r  c                     sH   t    fdd} | ddd | ddd | ddd | ddd d S )	Nc                    s|   | |d}t j|d  dd|}W d    n1 sw   Y  t|j dk| ks/J t|j dk|ks<J d S )N)zxtick.minor.visiblezytick.minor.visibler  r   r   )ri   rX   Zadd_subplotrv   rm   get_minor_ticksr   )ZxminorZyminorr  r  rp   ro   r.   r/   minorticksubplot  s   z,test_minorticks_rc.<locals>.minorticksubplotFr   Tr   r>   r[   )ri   Zfigure)r  r.   r  r/   test_minorticks_rc  s   	r  z%remove_overlapping_locs, expected_num))Tr   )Nr   )Fr   c                 C   sB  t jdddd}t t|}t \}}||| |jt	j
  |jt	j
d |jt	j
d |jt	j
d |jd | d urP| |j_|jj}||j ks]J tj|j|d	 |jj}||jjksqJ t|j |ks|J t|j |ksJ t|j |ksJ t|j |d
 ksJ d S )Nz
2018-11-03z
2018-11-06Z
datetime64r(  z
%a)r   r   r&     z%H:%Mr   )remove_overlapping_locsr   )r6   r8   Zonesrv   ri   rj   r  rm   r  rW   ZdatesZ
DayLocatorr  ZDateFormatterrt   ZHourLocatorrs  r  r  Zget_remove_overlapping_locsZsetprw   Zget_minorticklabelsZget_minorticklines)r  Zexpected_numtr~   ro   rp   Zcurrentnewr.   r.   r/   test_remove_overlap,  s(   r  subhiZaardvark)r   r   c                 C   sB   t  }tt ||  W d    d S 1 sw   Y  d S r  )r&   r   r9   r   r   r   )r  llr.   r.   r/   test_bad_locator_subsQ  s   "r  r@   )r   r   r>   r   r>  c              	   C   sR   t  }|j| d dD ]}|d|}tt|dddk s&J qd S )Nr?   )r   r   r      r   r%  r   r   r   r      r   )r&   r   rH   r(   r6   Zdiffr   r   )r@   r  topr   r.   r.   r/   test_small_range_loglocatorZ  s   &r  )7
contextlibr   r   r  r  Znumpyr6   Znumpy.testingr   r   r9   Z
matplotlibrW   Zmatplotlib.pyplotZpyplotri   Zmatplotlib.tickerZtickerr&   r   r<   rK   r_   r   r   r   r   r   r   r   r   r  r  r6  r;  rB  rz  r  r  r  r  r  r  r  r  r  r  r:   r;   r  Zzerosr  r@  rA  r  r.   r.   r.   r/   <module>   sl    "g&  
! N 3qE
!

