a
    ï½„gUG  ã                
   @  sº  d dl mZ d dlmZmZmZ d dlZd dlm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 d d
lmZ d dlZd dlm  mZ d dlmZ d dlm Z m!Z! d dl"m#Z# d dl$m%Z% d dl&m'Z'm(Z(m)Z) e�r(d dl*m+Z+ d dl,m-Z- d dl.m/Z/ d dl0m1Z1 d dl2m3Z3 dddddœdd„Z4G dd„ de ƒZ5ddœdd „Z6d1ddd#d$œd%d&„Z7d2d'd(dd#d)œd*d+„Z8d3d'd(dd#d)œd,d-„Z9d4dd'd(dd#ddd.œd/d0„Z:dS )5é    )Úannotations)ÚTYPE_CHECKINGÚLiteralÚ
NamedTupleN)Úsetp)Úlib)Úcache_readonly)Úfind_stack_level)Úis_dict_like)Ú	ABCSeries©Úremove_na_arraylike©Úpprint_thing)ÚLinePlotÚMPLPlot)Úcreate_iter_data_given_by)Úget_standard_colors)Úcreate_subplotsÚflatten_axesÚmaybe_adjust_figure)Ú
Collection)ÚAxes)ÚFigure)ÚLine2D)ÚMatplotlibColorr   z	list[str]ÚboolÚNone)ÚaxÚlabelsÚis_verticalÚreturnc                 K  s€   |r|   ¡ n|  ¡ }t|ƒt|ƒkrRtt|ƒt|ƒƒ\}}|dksJJ |ƒ‚||9 }|rj| j|fi |¤Ž n| j|fi |¤Ž dS )zãSet the tick labels of a given axis.

    Due to https://github.com/matplotlib/matplotlib/pull/17266, we need to handle the
    case of repeated ticks (due to `FixedLocator`) and thus we duplicate the number of
    labels.
    r   N)Z
get_xticksZ
get_yticksÚlenÚdivmodZset_xticklabelsZset_yticklabels)r   r   r    ÚkwargsZticksÚiÚ	remainder© r'   úf/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/pandas/plotting/_matplotlib/boxplot.pyÚ_set_ticklabels/   s    r)   c                      s  e Zd Zeddœdd„ƒZdZdZG dd„ deƒZd6d
ddœdd„Z	e
d7ddd
dœdd„ƒZdd„ Zedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd „ ƒZd8d"dd#œd$d%„Zddœd&d'„Zd(dd)œd*d+„Zddœd,d-„Zddd.œd/d0„Zed1dœd2d3„ƒZe‡ fd4d5„ƒZ‡  ZS )9ÚBoxPlotzLiteral['box']©r!   c                 C  s   dS )NÚboxr'   ©Úselfr'   r'   r(   Ú_kindB   s    zBoxPlot._kindÚ
horizontal)NÚaxesÚdictÚbothc                   @  s   e Zd ZU ded< ded< dS )z
BoxPlot.BPr   r   zdict[str, list[Line2D]]ÚlinesN)Ú__name__Ú
__module__Ú__qualname__Ú__annotations__r'   r'   r'   r(   ÚBPJ   s   
r9   r1   Ústrr   )Úreturn_typer!   c                 K  sN   || j vrtdƒ‚|| _tj| |fi |¤Ž | jrJ| jdkrDd| _nd| _d S )Nz2return_type must be {None, 'axes', 'dict', 'both'}ÚverticalF)	Ú_valid_return_typesÚ
ValueErrorr;   r   Ú__init__ÚsubplotsÚorientationÚsharexÚsharey)r.   Údatar;   r$   r'   r'   r(   r?   O   s    

zBoxPlot.__init__Nr   z
np.ndarray)r   Úyr;   c                 K  sx   |j dkr(dd„ |D ƒ}dd„ |D ƒ}nt|ƒ}|j|fi |¤Ž}|dkrR||fS |dkrl| j||d�|fS ||fS d S )Né   c                 S  s   g | ]}t |ƒ‘qS r'   r   ©Ú.0Úvr'   r'   r(   Ú
<listcomp>f   ó    z!BoxPlot._plot.<locals>.<listcomp>c                 S  s(   g | ] }|j d kr|nt tjg¡‘qS )r   )ÚsizeÚnpÚarrayÚnanrG   r'   r'   r(   rJ   j   rK   r2   r3   ©r   r4   )Úndimr   Úboxplotr9   )Úclsr   rE   Ú
column_numr;   ÚkwdsZysÚbpr'   r'   r(   Ú_plot`   s    
zBoxPlot._plotc                 C  sb   |t ju rd S |d ur&tjdtƒ d� t|tƒr^g d¢}|D ] }||vr<td|› d|› �ƒ‚q<|S )NzC'color' and 'colormap' cannot be used simultaneously. Using 'color')Ú
stacklevel©ÚboxesÚwhiskersÚmediansÚcapsú!color dict contains invalid key 'ú'. The key must be either )r   Z
no_defaultÚwarningsÚwarnr	   Ú
isinstancer2   r>   )r.   ÚcolorÚcolormapÚ
valid_keysÚkeyr'   r'   r(   Ú_validate_color_argsv   s"    
ý
ÿÿzBoxPlot._validate_color_argsc                 C  s   t d| jd d�S )Né   )Ú
num_colorsrd   rc   )r   rd   r-   r'   r'   r(   Ú_color_attrs‹   s    zBoxPlot._color_attrsc                 C  s
   | j d S ©Nr   ©rj   r-   r'   r'   r(   Ú_boxes_c“   s    zBoxPlot._boxes_cc                 C  s
   | j d S rk   rl   r-   r'   r'   r(   Ú_whiskers_c—   s    zBoxPlot._whiskers_cc                 C  s
   | j d S )NrF   rl   r-   r'   r'   r(   Ú
_medians_c›   s    zBoxPlot._medians_cc                 C  s
   | j d S rk   rl   r-   r'   r'   r(   Ú_caps_cŸ   s    zBoxPlot._caps_crc   zQdict[str, MatplotlibColor] | MatplotlibColor | Collection[MatplotlibColor] | None)Ú
color_kwdsr!   c                 C  s   d S ©Nr'   )r.   ri   rq   r'   r'   r(   Ú_get_colors£   s    zBoxPlot._get_colorsc                 C  s¤   t | jtƒrN| j d| j¡}| j d| j¡}| j d| j¡}| j d| j¡}n0| jpX| j}| jpd| j}| jpp| j}| jp|| j}||||f}t|fd|i| j	¤Ž d S )NrZ   r[   r\   r]   Ú	color_tup)
rb   rc   r2   Úgetrm   rn   ro   rp   Úmaybe_color_bprU   )r.   rV   rZ   r[   r\   r]   rt   r'   r'   r(   rv   ­   s    zBoxPlot.maybe_color_bpr   )Úfigr!   c                 C  sŠ  | j rôtjtd�| _| jd ur,t| j| jƒn| j}t	| j
|d�ƒD ]®\}\}}|  |¡}| j ¡ }| jd urž|j}| t|ƒ¡ | jjj}dd„ |d D ƒ}	n
t|ƒg}	| j||f|| jdœ|¤Ž\}
}|  |¡ |
| j|< t||	| jdkd� qBn’| jjj}|  d¡}| j ¡ }| j||fd| jdœ|¤Ž\}
}|  |¡ |
| _d	d„ | jjD ƒ}| j�srd
d„ tt|ƒƒD ƒ}t||| jdkd� d S )N©Zdtype)rD   c                 S  s   g | ]}t |ƒ‘qS r'   r   )rH   Úcolr'   r'   r(   rJ   Ú   rK   z&BoxPlot._make_plot.<locals>.<listcomp>r   )rT   r;   r<   )r   r   r    c                 S  s   g | ]}t |ƒ‘qS r'   r   )rH   Úleftr'   r'   r(   rJ   ñ   rK   c                 S  s   g | ]}t |ƒ‘qS r'   r   )rH   rf   r'   r'   r(   rJ   ó   rK   )r@   ÚpdÚSeriesÚobjectÚ_return_objÚbyr   rD   r/   Ú	enumerateZ
_iter_dataZ_get_axrU   ÚcopyÚTÚ	set_titler   ÚcolumnsÚlevelsrW   r;   rv   r)   rA   ÚvaluesZ	use_indexÚranger"   )r.   rw   rD   r%   ÚlabelrE   r   rU   r…   Z
ticklabelsÚretrV   r   r'   r'   r(   Ú
_make_plot¾   sZ    ÿý	




ÿÿÿ


ÿ



ÿÿÿ

ÿzBoxPlot._make_plotc                 C  s   d S rr   r'   r-   r'   r'   r(   Ú_make_legendø   s    zBoxPlot._make_legend)r   r!   c                 C  s0   | j r| t| j ƒ¡ | jr,| t| jƒ¡ d S rr   )ÚxlabelÚ
set_xlabelr   ÚylabelÚ
set_ylabel)r.   r   rD   r'   r'   r(   Ú_post_plot_logicû   s    zBoxPlot._post_plot_logicz!Literal['horizontal', 'vertical']c                 C  s   | j  dd¡rdS dS d S )NÚvertTr<   r0   )rU   ru   r-   r'   r'   r(   rA     s    zBoxPlot.orientationc                   s   | j d u rtƒ jS | jS d S rr   )r;   ÚsuperÚresultr~   r-   ©Ú	__class__r'   r(   r“   	  s    
zBoxPlot.result)r1   )Nr1   )Nrc   )r5   r6   r7   Úpropertyr/   Z_layout_typer=   r   r9   r?   ÚclassmethodrW   rg   r   rj   rm   rn   ro   rp   rs   rv   rŠ   r‹   r�   rA   r“   Ú__classcell__r'   r'   r”   r(   r*   A   s>    ÿ




  ú
:r*   r+   c                 K  s„   |  d¡s t| d |d dd� |  d¡s@t| d |d dd� |  d¡s`t| d	 |d
 dd� |  d¡s€t| d |d dd� d S )NZboxpropsrZ   r   é   )rc   ÚalphaZwhiskerpropsr[   Zmedianpropsr\   rF   Zcappropsr]   rh   )ru   r   )rV   rt   rU   r'   r'   r(   rv     s    



rv   TFztuple[float, float] | None)Únumeric_onlyÚgridÚfigsizec
                 K  st  |j |dd�}|d u r:t|ttfƒs*|g}| ¡ j |¡}t|ƒ}t||
 	dd¡|
 	dd¡|||d�\}}t
|ƒ}|
 	dd ¡|
 	dd ¡ }}|
 d	d¡r¢|pž|}n|p¨|}g }t|ƒD ]\\}}|| }|| }t|Ž \}}| |||f||d
œ|
¤Ž}| |¡ | |¡ | |¡ q¶tj||dd�}|	d u �r2|}t|ƒdk�rH|d n|}| d|› �¡ t|dddddd� |S )NF)ZobservedrB   TrC   )ÚnaxesrB   rC   r�   r   ÚlayoutrŒ   rŽ   r‘   )rŒ   rŽ   )Úindexr�   r™   r   zBoxplot grouped by ç333333Ã?çÍÌÌÌÌÌì?çš™™™™™¹?çš™™™™™É?©ÚbottomÚtoprz   ÚrightZwspace)Úgroupbyrb   ÚlistÚtupleÚ_get_numeric_datar„   Ú
differencer"   r   Úpopr   ru   r€   Úziprƒ   Úappendrœ   r{   r|   Zsuptitler   )ZplotfrD   r„   r   r›   rœ   r�   r   rŸ   r;   r$   Úgroupedrž   rw   r1   Z_axesrŒ   rŽ   Z	ax_valuesr%   ry   Zgp_colÚkeysr†   Zre_plotfr“   Zbyliner'   r'   r(   Ú_grouped_plot_by_column  sF    

ú
	



r³   z
int | NoneÚint)ÚfontsizeÚrotrœ   r�   c
              
     s†  dd l m} ˆtjvrtdƒ‚t| tƒr6|  d¡} d}‡fdd„}ddœ‡ ‡‡‡fdd	„}|ƒ ‰ |d u rnd }nt|tt	fƒr‚|}n|g}|d ur´t
|| f||||||ˆd
œˆ¤Ž}nÎˆd u rÀd‰|d urÐtdƒ‚|d u �r"|d urêd|ini }| |¡� | ¡ }W d   ƒ n1 �s0    Y  |  ¡ } t| jƒ}|dk�rFtdƒ‚|d u �rX| j}n| | } ||| jj|fi ˆ¤Ž}| |¡ |S )Nr   z,return_type must be {'axes', 'dict', 'both'}Úxc                    s¤   t dd�} t | g d¢¡} t | d¡} ˆ  dd ¡}|r t|ƒr–g d¢}tt|tdƒƒƒ}| 	¡ D ]2\}}||v r~|| || < q`t
d|› d	|› �ƒ‚q`n
|  |¡ | S )
Nrh   )ri   )r   r   rF   Úkrc   rY   é   r^   r_   )r   rM   Ztaker°   r®   r
   r2   r¯   r‡   Úitemsr>   Úfill)r“   Úcolorsre   Zkey_to_indexrf   Úvalue)rU   r'   r(   rs   r  s$    
ÿÿ
zboxplot.<locals>._get_colorsr   )r   c                   sØ   |  dd ¡|  dd ¡ }}|r,| t|ƒ¡ |r>| t|ƒ¡ dd„ | D ƒ} dd„ |D ƒ}|j|fi |¤Ž}ˆd ur‚|jdˆd� t|| | dd	¡ˆd
� t|fdˆ i|¤Ž ˆdkrº|S ˆdkrÐt	j
||d�S |S d S )NrŒ   rŽ   c                 S  s   g | ]}t |ƒ‘qS r'   r   )rH   r·   r'   r'   r(   rJ   —  rK   z/boxplot.<locals>.plot_group.<locals>.<listcomp>c                 S  s   g | ]}t jt|ƒtd �‘qS )rx   )rM   Zasarrayr   r}   rG   r'   r'   r(   rJ   ˜  rK   r3   )ÚaxisZ	labelsizer‘   T)r   r   r    Zrotationrt   r2   rP   )r®   r�   r   r�   rR   Ztick_paramsr)   ru   rv   r*   r9   )r²   r†   r   rU   rŒ   rŽ   rV   )r¼   rµ   r;   r¶   r'   r(   Ú
plot_group�  s&    ÿzboxplot.<locals>.plot_group)r„   r   rœ   r�   r   rŸ   r;   r1   z7The 'layout' keyword is not supported when 'by' is Nonezfigure.figsizez;boxplot method requires numerical columns, nothing to plot.)Úmatplotlib.pyplotÚpyplotr*   r=   r>   rb   r   Zto_framerª   r«   r³   Z
rc_contextZgcar¬   r"   r„   r†   r‚   rœ   )rD   Úcolumnr   r   rµ   r¶   rœ   r�   rŸ   r;   rU   Úpltrs   r¿   r„   r“   Úrcrž   r'   )r¼   rµ   rU   r;   r¶   r(   rR   [  sb    


þ÷
ö
(

ÿ

rR   c
                 K  s<   dd l m} t| f|||||||||	dœ	|
¤Ž}| ¡  |S )Nr   )	rÂ   r   r   rµ   rœ   r¶   r�   rŸ   r;   )rÀ   rÁ   rR   Zdraw_if_interactive)r.   rÂ   r   r   rµ   r¶   rœ   r�   rŸ   r;   rU   rÃ   r'   r'   r(   Úboxplot_frameÝ  s$    ÿöõrÅ   )r@   rµ   r¶   rœ   r�   rB   rC   c              
   K  sF  |du r t | ƒ}t|d||	|
||d�\}}t|ƒ}tjtd�}t| |ƒD ]@\\}}}|jf |||||dœ|¤Ž}| t	|ƒ¡ ||j
|< qHt|ddddd	d
� n¢t| Ž \}}| jdkrÈtj||dd�}n,t |ƒdkrì|d  |dd … ¡}n|d }|d u�r"t |¡}tj ||g¡}t|jƒ}|jf |||||||dœ|¤Ž}|S )NTF)rž   Zsqueezer   rB   rC   r�   rŸ   rx   )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¯   rR   rƒ   r   Úlocr   r¾   ÚconcatÚjoinÚcomZconvert_to_list_likeZ
MultiIndexZfrom_productrª   r†   )r±   r@   rÂ   rµ   r¶   rœ   r   r�   rŸ   rB   rC   rU   rž   rw   r1   r‰   rf   ÚgroupÚdr²   ÚframesÚdfZ	multi_keyr'   r'   r(   Úboxplot_frame_groupbyý  sX    ù
	
ÿÿ



ùø
rÎ   )NNTFNNNN)	NNNNr   TNNN)	NNNNr   TNNN)
TNNr   TNNNFT);Ú
__future__r   Útypingr   r   r   r`   Zmatplotlib.artistr   ÚnumpyrM   Zpandas._libsr   Zpandas.util._decoratorsr   Zpandas.util._exceptionsr	   Zpandas.core.dtypes.commonr
   Zpandas.core.dtypes.genericr   Zpandas.core.dtypes.missingr   Zpandasr{   Zpandas.core.commonÚcoreÚcommonrÉ   Zpandas.io.formats.printingr   Z pandas.plotting._matplotlib.corer   r   Z#pandas.plotting._matplotlib.groupbyr   Z!pandas.plotting._matplotlib.styler   Z!pandas.plotting._matplotlib.toolsr   r   r   Úcollections.abcr   Zmatplotlib.axesr   Zmatplotlib.figurer   Zmatplotlib.linesr   Zpandas._typingr   r)   r*   rv   r³   rR   rÅ   rÎ   r'   r'   r'   r(   Ú<module>   sˆ    Q        ö?         ö          ö"          õ