U
    Kvf ;                     @   sj   d dl Zd dlZd dlZd dlmZ dZzd dlm	Z
 W n ek
rL   Y nX dd Zejjdd ZdS )    N)dot_plotFc                 C   s   t r| | t| d S )N)
pdf_outputZsavefigpltclose)pdffig r   K/tmp/pip-unpacked-wheel-2v6byqio/statsmodels/graphics/tests/test_dotplot.pyclose_or_save   s    
r
   c                    s  t rddlm} |d}nd }t  td}t }t||d}|d t	|| t  td}t }t||dd}|d	 t	|| tj
d
d t }td}t||d}|d |d t	|| tj
dd t }td}t||dd}|d |d t	|| tj
d
d t }td}t||dd}|d |dd t	|| tj
dd t }td}t||ddd}|d |dd t	|| t
  t }td}t||d}|d t	|| t
  t }td}t||dd}|d t	|| t
  t }td}t||d}|dd |d t	|| t  t }dd tdD }tjjdd }t|||d!}|d" t	|| t  t }tjjdd }d#d tdD }t|||d$d%}|d& t	|| t  td'd'd(d)g}tjjdd }d*d tdD }t|||d$dd+}|d,}	|	d- t	|| t  td'd.d/d0g}tjjdd }ttd1tdtj}ttd1tdtj}
d2d3 tdD }t|||
||d4}|d5 t	|| t  t }td}t|td|d6}|d7 t	|| t  t }ttd}ttd}t|||d6}|d8 t	|| t  t }td}d9d tdD }t|||d6}|d: t	|| t  t }td}d;d tdD }t|||dd<}|d= t	|| t  t }td}d>d tdD }dd?d@dAi}t||||dB}|dC t	|| t  td'd'dDd)g}d1tjjdd  }ttddE}dFd tdD }ttddGtj}
dHd |
D }
t||||
|ddI}| \}}tj||dJdKdLdM}|d |dN t	|| t  td'd'dDd)g}t||||
|ddOdPgdQ}| \}}tj||dJdKdLdM}|d |dR t	|| t  td'd'dDd)g}d1tjjdd  }ttddE}dSd tdD }ttddGtj}
dTd |
D }
t||||
|dddU}| \}}tj||dJdKdLdM}|d |dV t	|| t  td'd'dDd)g}dOdPg}t||||
|dd|dW}| \}}tt||  fdXd|D }tj||dJdKdLdM}|d |dY t	|| t  td'd'dDd)g}d1tjjdd  }ttddE}dZd tdD }ttddGtj}
d[d |
D }
t||||
|dddd\}| \}}tj||dJdKdLdM}|d td]d |dV t	|| t  td'd'dDd)g}d1tjjdd  }ttddE}d^d tdD }ttddGtj}
d_d |
D }
d`daid`dbidc}d`daid`dbidc}t||||
|d||dd}| \}}tj||dJdKdLdM}|d |de t	|| t  td'd'dDd)g}d1tjjdd  }ttddE}dfd tdD }ttddGtj}
dgd |
D }
d`daid`dbidc}d`daid`dbidc}t||||
|d||ddh	}| \}}tj||dJdKdLdM}|d |de t	|| t  t }td}ttdidEtj}ttdidGtj}
tdjtdktj}dld |D }t|||
||dm}|dn t	|| t  td'd'dodDg}td}ttdidEtj}ttdidGtj}
tdjtdktj}dpd |D }t|||
||ddq}|dr}	|	ds t	|| t  t }td}ttdidEtj}ttdidGtj}
tdjtdktj}dtd |D }t|||
||dudvdwgdx}|dy t	|| t
  t }td}dzd{d|d}g}d{d|dzd}g}t||||d~}|d t	|| t  td}dd tdD }dd }dd }t }t|||d$||d}|d t	|| t  td}dd tdD }t }t|||d$dd}|d t	|| t  td'd'dDd)g}d1tjjdd  }g }d}t |dk rfttj!dKdD ]}|"| qH|dK7 }q(ttddGtj}
dd |
D }
t|||
|dd}| \}}tj||dJdKdLdM}|d |d t	|| t r|#  d S )Nr   )PdfPagesztest_dotplot.pdf   )axzBasic horizontal dotplotF)r   
horizontalzBasic vertical dotplot)      )Zfigsize(   zTall and skinny dotplotzx axis label)r   r   zShort and wide dotplotzy axis labelT)r   stripedzTall and skinny striped dotploti2   )r   r   r   zShort and wide striped dotplotr   z'Basic horizontal dotplot with few linesz%Basic vertical dotplot with few lines   z&Dotplot with adjusted horizontal rangec                 S   s   g | ]}d t jdd qS )ABCDEFGHr      )nprandomrandint.0kr   r   r	   
<listcomp>o   s     ztest_all.<locals>.<listcomp>)size)linesr   z4Dotplot with user-supplied labels in the left marginc                 S   s.   g | ]&}d t jdd d t|d  qS r   r   r   ::   r   r   r   strr   r   r   r	   r   y   s   r!   )r   r   split_namesz1Dotplot with user-supplied labels in both marginsg?g)\(?g?c                 S   s.   g | ]&}d t jdd d t|d  qS r    r#   r   r   r   r	   r      s   )r   r   r%   r   z:Vertical dotplot with user-supplied labels in both margins)      ?g(\?gQ?g(\?g333333?   c                 S   s$   i | ]}|d | d| dddqS )ZrgbcZosvp   g333333?)colormarkermsalphar   r   r   r   r	   
<dictcomp>   s     ztest_all.<locals>.<dictcomp>)r   stylesr   marker_propsz&Dotplot with custom colors and symbols)	intervalsr   z Dotplot with symmetric intervalsz0Dotplot with symmetric intervals (Pandas inputs)c                 S   s   g | ]}d qS )r"      r   r   ir   r   r	   r      s     z#Dotplot with nonsymmetric intervalsc                 S   s   g | ]}d qS r1   r   r3   r   r   r	   r      s     )r0   r   r   z,Vertical dotplot with nonsymmetric intervalsc                 S   s   g | ]}d qS r1   r   )r   xr   r   r	   r      s     Z	lightgreyround)r)   Zsolid_capstyle)r0   
line_propsr   z#Dotplot with custom line propertiesg      ?)r"   r"   c                 S   s   g | ]}d qS r1   r   r   r   r   r	   r      s     )r   r"   c                 S   s   g | ]}d dg| qS CatDogr   r3   r   r   r	   r      s     )r0   r   r.   r   stackedzcenter rightr"   g-C6?)locZ	numpointsZhandletextpadz Dotplot with two points per liner:   r9   )r0   r   r.   r   r;   styles_orderz0Dotplot with two points per line (reverse order)c                 S   s   g | ]}d qS r1   r   r   r   r   r	   r      s     c                 S   s   g | ]}d dg| qS r8   r   r3   r   r   r	   r      s     )r0   r   r.   r   r;   r   z)Vertical dotplot with two points per line)r0   r   r.   r   r;   r   r=   c                    s   g | ]} | qS r   r   )r   lZlhr   r	   r      s     z9Vertical dotplot with two points per line (reverse order)c                 S   s   g | ]}d qS r1   r   r   r   r   r	   r   
  s     c                 S   s   g | ]}d dg| qS r8   r   r3   r   r   r	   r     s     )r0   r   r.   r   r;   r   r   ic                 S   s   g | ]}d qS r1   r   r   r   r   r	   r     s     c                 S   s   g | ]}d dg| qS r8   r   r3   r   r   r	   r     s     r)   ZorangeZpurpler8   )r0   r   r.   r   r;   r/   r7   z/Dotplot with color-matched points and intervalsc                 S   s   g | ]}d qS r1   r   r   r   r   r	   r   2  s     c                 S   s   g | ]}d dg| qS r8   r   r3   r   r   r	   r   4  s     )r0   r   r.   r   r;   r/   r7   r      )r   r"      
   c                 S   s   g | ]}d ddg| qS AxxByyCzzr   r   r   r   r	   r   J  s     )r   r.   sectionsr   zDotplot with sectionsg?c                 S   s   g | ]}d ddg| qS rC   r   r   r   r   r	   r   V  s     )r   r.   rG   r   r   zVertical dotplot with sections)r&   gHzG?c                 S   s   g | ]}d ddg| qS rC   r   r   r   r   r	   r   d  s     rE   rD   rF   )r   r.   rG   r   Zsection_orderz(Dotplot with sections in specified orderABCD)r   
line_orderr   zDotplot with reordered linesc                 S   s   g | ]}d |d| f qS z%d::%dd   r   r3   r   r   r	   r   w  s     c                 S   s   d|  S )NZlft_r   r5   r   r   r	   <lambda>x      ztest_all.<locals>.<lambda>c                 S   s   d|  S )NZrgt_r   rO   r   r   r	   rP   y  rQ   )r   r   r%   Zfmt_left_nameZfmt_right_namez'Horizontal dotplot with name formattingc                 S   s   g | ]}d |d| f qS rM   r   r3   r   r   r	   r     s     right)r   r   r%   Z
show_nameszShow right names onlyc                 S   s   g | ]}d dg| qS r8   r   r3   r   r   r	   r     s     )r   r.   r   r;   z1Dotplot with different numbers of points per line)$r   Zmatplotlib.backends.backend_pdfr   r   ZclfrangeZaxesr   	set_titler
   figurer   ZarangeZ
set_xlabelZ
set_ylabelZset_xlimZset_ylimr   normalZset_positionZkronZonesZastypeZint32pdZSeriesZget_legend_handles_labelsZ	figlegendZ
draw_framedictzipZylimlenr   appendr   )Zclose_figuresZreset_randomstater   r   Zpointsr   r   valsr   txtr.   r/   r0   r7   ZhandleslabelsZlegr=   rG   rL   Zfmt_leftZ	fmt_rightiir   r   r?   r	   test_all   s   




















































 


  



  


   



   



  



   




  








 




 


r`   )Znumpyr   ZpandasrW   ZpytestZstatsmodels.graphics.dotplotsr   r   Zmatplotlib.pyplotZpyplotr   ImportErrorr
   markZ
matplotlibr`   r   r   r   r	   <module>   s   