a
    Sic%                 "   @   sX  d dl mZ d dlmZ d dlZd dlmZ d dlmZ d dl	Z
d dlZzd dlmZ dZW n" ey~   ddlmZ d	ZY n0 d dlZd d
lmZ d dlmZ d dlmZ d dlmZmZmZ d dl m!Z! d dl"m#Z# d dl$m%Z%m&Z&m'Z'm(Z( d dl)m*Z* d dl+m,Z,m-Z-m.Z.m/Z/ d dl0m1Z1m2Z2 g dZ3G dd de!Z4G dd de4Z5G dd dZ6G dd de6Z7G dd de6Z8G dd de6Z9G dd  d e9Z:G d!d" d"e9Z;G d#d$ d$e:Z<G d%d& d&e6Z=e>ed'ed(ed)ed*ed+ed,ed-ed.ed/ed0ed1ed2ed3ed4ed5ed6ed7ed8ed9ed:ed;ed<ed=ed>ed?ed@edAedBedCedDedEedFdG Z?e?@e2 ddddddddddHdId	dJddKddLdMdNZAedOjBf i e?eA_CdddddddPdQdRd	dSdIdTdd	dddddHddUdVdWZDedXjBf i e?eD_CddddddddddHdId	dYddZd[d\d	ddddd]d^d_ZEed`jBf i e?eE_Cddddddd	dddddJdad ddddbddcdddeZFedfjBf i e?eF_CdddddddddddJdad ddddbd\ddgdhdiZGedjjBf i e?eG_CdddddddkdldmddddddHdIdnddd	doddpdqdrZHedsjBf i e?eH_Cdddddddkdldmdddtdudd	ddddddoddddvdwdxZIedyjBf i e?eI_CddddddddddHdId	ddzd{d|ZJed}jBf i e?eJ_CddddddddkdldmdddddddJdd~dddddddbd	d	d	dddodddZKedjBf i e?eK_CG dd dZLdS )    )dedent)NumberN
rgb_to_hls)partial)gaussian_kdeF   T)PatchCollection)variable_typeinfer_orientcategorical_order)_RelationalPlotter)utils)	remove_na_normal_quantile_func_draw_figure_default_color)EstimateAggregator)color_palettehusl_palettelight_palettedark_palette)	FacetGrid_facet_docs)	catplot	stripplot	swarmplotboxplot
violinplot	boxenplot	pointplotbarplot	countplotc                       s   e Zd ZdZddddZddiZdZdgZdi ddd	d
f fdd	ZdddZ	dd Z
edd Zdd Zdd Zedd Zdd Zdd Z fddZ  ZS ) _CategoricalPlotterNew)xyhueunitsz@columnsz@valuesr$   r%   r&   r%   scattercolorNFautoc                    s<  t  j||d | jdkr|dkr| jjdddd| _t| j}| jdd }| jdd }	| jdd }
| jdd }d|v r|| jd< |
| jd< d|v r|	| jd< || jd< t	| j
dd | j
dd ||d| _|| _| jsd S | j| jvrd | j| j< d	| j| j< d
| j| j< t| j| j |}|| j| j< d S )N)data	variableswidehr%   r$   )r$   r%   columns)r$   r%   orientrequire_numericcategorical )super__init__input_format	plot_datarenamesetr-   pop	var_typesr   getr2   legendhas_xy_datacat_axisr   
var_levels)selfr,   r-   orderr2   r3   r?   Zorig_variablesZorig_xZorig_yZorig_x_typeZorig_y_typeZ
cat_levels	__class__ O/var/www/html/django/DPS/env/lib/python3.9/site-packages/seaborn/categorical.pyr7   8   s:    





z_CategoricalPlotterNew.__init__c                 C   s   |du p|du}|rd| j vr|rd| _| j| j | jd< | j | j | j d< d| jd< | j| j }t|trdd | D }nd| _d| j v r|du r|durt|t	st
j|}d| }d	| d
}t|t ||fS )a  Implement backwards compatibility for hue parametrization.

        Note: the force_hue parameter is used so that functions can be shown to
        pass existing tests during refactoring and then tested for new behavior.
        It can be removed after completion of the work.

        Nr&   Tr4   c                 S   s   i | ]\}}t ||qS rG   )str).0kvrG   rG   rH   
<dictcomp>       z:_CategoricalPlotterNew._hue_backcompat.<locals>.<dictcomp>Fzdark:ziSetting a gradient palette using color= is deprecated and will be removed in version 0.13. Set `palette='z'` for same effect.)r-   _redundant_huer9   rA   r=   rB   
isinstancedictitemsrI   mplcolorsto_hexwarningswarnFutureWarning)rC   r*   palette	hue_orderZ	force_hueZdefault_behaviormsgrG   rG   rH   _hue_backcompaty   s(    



z&_CategoricalPlotterNew._hue_backcompatc                 C   sx   d| j vrt|durtd}tj|tdd d| _| j| j | jd< | j | j| j d< | j| j| jd< | j	| j}|S )z?Provide one cycle where palette= implies hue= when not providedr&   Nz8Passing `palette` without assigning `hue` is deprecated.   )
stacklevelF)
r-   rV   rW   rX   r?   r9   rA   r>   r=   rB   )rC   rY   rZ   r[   rG   rG   rH   _palette_without_hue_backcompat   s    z6_CategoricalPlotterNew._palette_without_hue_backcompatc                 C   s   ddd| j  S )Nr$   r%   rL   r/   )r2   rC   rG   rG   rH   rA      s    z_CategoricalPlotterNew.cat_axisc                 C   s>   t |sdS tj|dd}dd |D }t|d }|||fS )z1Get a grayscale value that looks good with color.Nr   axisc                 S   s    g | ]}t |d d  d qS )Nr]   r   r   )rJ   rgbrG   rG   rH   
<listcomp>   rN   z4_CategoricalPlotterNew._get_gray.<locals>.<listcomp>333333?)lennpuniquemin)rC   rT   Zunique_colors
light_valslumrG   rG   rH   	_get_gray   s    z _CategoricalPlotterNew._get_grayc                 C   s   | j | dkrdS | j| jr"dS tt|d| d }|dkrd|jd |jd|d dd	 n |jd |j	|d ddd	 dS )
z0Set ticks and limits for a categorical variable.r4   Nget_ticksr$   F            ?r+   )
r=   r9   emptyrg   getattrxaxisgridset_xlimyaxisset_ylim)rC   axrc   nrG   rG   rH   _adjust_cat_axis   s    z'_CategoricalPlotterNew._adjust_cat_axisc                 C   s8   t | j| j }t|dkr0t t |}nd}|S )zCReturn unit of width separating categories on native numeric scale.r   )rh   ri   	comp_datarA   rg   nanmindiff)rC   Zunique_valuesZnative_widthrG   rG   rH   _native_width   s
    z$_CategoricalPlotterNew._native_widthc                 C   sT   d}d| j v rPt| jj}|rF|| }td|| |}|| 8 }n
t|}|S )z3Return offsets for each hue level for dodged plots.Nr&   r   )r-   rg   _hue_maplevelsrh   linspacemeanzeros)rC   widthdodgeoffsetsn_levels
each_widthrG   rG   rH   _nested_offsets   s    

z&_CategoricalPlotterNew._nested_offsetsc                 C   s  d| j  }| ||}|du r$d}nt|}d| jv rJ|rJ|t| jj }|| j 9 }ttj	j
| |
 d}	| jg}
|r|
d | j}d }}| j|
dddD ]\}}|d ur|dk r||d | jjj }t|dkr|	t|d	nd}|| j | | }||| j< d
D ]&}| |rtd|| ||< q| |}|j|d |d fd|i|}d| jv r|| |d  |dkr|| |  q|| q| jdkr| j o| jdk}n
t| j}|r| | | \}}|r|j| j d d S )N皙?Tg?r&   )lowhighr   from_comp_dataallow_emptyr   )sizexy
   r$   r%   r*   grayr+   r.   title)!r   r   floatr-   rg   r   r   r   rh   randomuniformrA   appendrz   	iter_dataanymapindex_log_scaledpower	_get_axesr)   set_facecolorsset_edgecolorsrm   get_facecolorsr?   rO   r8   booladd_legend_dataget_legend_handles_labelslegend_title)rC   jitterr   r*   	edgecolorplot_kwsr   r   ZjlimZjitterer	iter_varsrz   
dodge_moveZjitter_movesub_varssub_dataZadjusted_datavarpointsshow_legendhandles_rG   rG   rH   plot_strips   sR    	




 


z"_CategoricalPlotterNew.plot_stripsc                    s  dj  }||}jg}|r,|d j i }	d}
j|dddD ]\}}|d urr||d jjj	 }
|j
s|j |
 |j< dD ]"}|rtd|| ||< q|  j|d |d	 fd
|i|}djv r||d  |dkr||  n
|| |j
sJ||	 |j jd f< qJt|j|d|	 D ]F\\ }}| jd dkr^|d fdd
}|||_q^t j jdkr҈j  oΈj!dk}n
t"j}|r#   $ \}}|r jj%d d S )Nr   r&   r   Tr   r   r   r$   r%   r*   r   )r   r2   warn_threshr   )centerc                   s   | | j dkr"d} }n }d}jj dk}| j |sj|s\|rjj||d t	| j
| | d S )Nr/   Fr4   scalexscaley)r2   get_autoscaley_onget_autoscalex_onr=   rA   update_datalimget_datalim	transDataautoscale_viewr6   rF   draw)r   rendererr   r   r   Zfixed_scale)rF   rz   beeswarmrC   rG   rH   r   w  s    


z0_CategoricalPlotterNew.plot_swarms.<locals>.drawr+   r.   r   )&r   r   rA   r   rz   r   r   r   r   r   rs   r   rh   r   r   r)   r-   r   r   rm   r   ilocBeeswarmr2   rR   get_offsetsshape__get__r   r   figurer?   rO   r8   r   r   r   r   )rC   r   r*   r   r   r   r   r   r   Zpoint_collectionsr   r   r   r   r   r   r   r   r   r   rE   )rz   r   rC   rH   plot_swarmsA  sX    	



 





z"_CategoricalPlotterNew.plot_swarms)F)__name__
__module____qualname__	semanticswide_structureflat_structure_legend_func_legend_attributesr7   r\   r_   propertyrA   rm   r|   r   r   r   r   __classcell__rG   rG   rE   rH   r#   ,   s.   A
1
	
	Br#   c                   @   s   e Zd Zejd ZdS )_CategoricalFacetPlotter)colrowN)r   r   r   r#   r   rG   rG   rG   rH   r     s   r   c                   @   sZ   e Zd ZdZdZdZdddZdd Zd	d
 Ze	dd Z
e	dd Zdd Zdd ZdS )_CategoricalPlotterr   lightTNc	                    s  |du r|du r|dur(d}	t |	d}
d}d}d}d}d}t tjr|du r|g } D ]}t | dkr\|| q\ | }|} jj}| }dd |D }n|durd}	t |	t	 drVt
 jdkrt d	 r g}nt }n^t
 jd
krH j\}}|dks$|dkr0  g}n fddt|D }nd}	t |	n. du rhg g}nt d	 r g}n }dd |D }ttt
|}t|drdnd}n dur ||} ||} ||} ||}||||fD ]&}t|trd| d}t |qt|||| jd}|du sR|du r|du r`|n|}t|g}t	|dr|j}nd}d}d}g }d}
d}d}d}n|dkr|| }}n
|| }}d}t	|dr|j}t||}| |||\}}|du rd}
d}d}nt||}| |||\}
}|du r<d}n| |||\}}|| _|| _|| _|| _|| _|
| _|| _|| _ || _!dS )z9Convert input specification into a common representation.Nz$Cannot use `hue` without `x` and `y`numericc                 S   s   g | ]\}}t |tqS rG   rh   asarrayr   )rJ   rK   srG   rG   rH   re     rN   z;_CategoricalPlotter.establish_variables.<locals>.<listcomp>z-Input data must be a pandas object to reorderr   r   r      c                    s   g | ]} d d |f qS NrG   rJ   ir,   rG   rH   re     rN   z/Input `data` can have no more than 2 dimensionsc                 S   s   g | ]}t |tqS rG   r   )rJ   drG   rG   rH   re     rN   r/   rL   zCould not interpret input '')r3   name)"
ValueErrorrP   pd	DataFramer
   r   r1   r   rR   hasattrrg   r   rh   isscalarlistravelrangerI   
startswithr>   r   r3   r   r   _group_longformr2   r9   group_labelvalue_labelgroup_names	plot_hues	hue_title	hue_names
plot_units)rC   r$   r%   r&   r,   r2   rD   rZ   r'   errorr   r   r   r   r   r   r   r9   r   r   nrncr   errvalsgroupsr   rG   r   rH   establish_variables  s    	



	







z'_CategoricalPlotter.establish_variablesc           
   	   C   s   t |tjs2t |tjr |j}nd}tj||d}||}g }|D ]:}z||}W n tyr   tg }Y n0 |	| qD|j
}	||	fS )z9Group a long-form variable by another with correct order.N)r   )rP   r   Seriesr   groupby	get_groupKeyErrorrh   arrayr   r   )
rC   r   grouperrD   r   Zgrouped_valsZout_datagZg_valslabelrG   rG   rH   r   v  s    
z#_CategoricalPlotter._group_longformc                    sJ  | j du rt| j}n
t| j }|du r^ du r^t }|t|krPt|d}qt|dd}n du r| j du r||g| }q| jdkrt||}q| jdkrt	||}qt
dn>t tr| j du r| j}n| j } fdd	|D  t |}|d
k rt||d}t|}dd	 |D }	t|	d }
tj|
|
|
f}|| _|| _dS )z9Get a list of colors for the main component of the plots.N)n_colorsgffffff?)lr   darkzNo default palette specifiedc                    s   g | ]} | qS rG   rG   )rJ   r  rY   rG   rH   re     rN   z8_CategoricalPlotter.establish_colors.<locals>.<listcomp>r   )desatc                 S   s   g | ]}t | d  qS )r   r   rJ   crG   rG   rH   re     rN   rf   )r   rg   r9   r   get_color_cycler   r   default_paletter   r   RuntimeErrorrP   rQ   r   rj   rS   rT   rgb2hexr   )rC   r*   rY   
saturationr  current_paletterT   r   Z
rgb_colorsrk   rl   r   rG   r
  rH   establish_colors  s<    









z$_CategoricalPlotter.establish_colorsc                 C   sJ   t | j}| jr<| j| }td| j| |}|| 8 }n
t|}|S )z>A list of center positions for plots when hue nesting is used.r   )rg   r   r   r   rh   r   r   r   )rC   r   r   r   rG   rG   rH   hue_offsets  s    


z_CategoricalPlotter.hue_offsetsc                 C   s&   | j r| jt| j d }n| j}|S )AA float with the width of plot elements when hue nesting is used.g\(\?r   r   rg   r   rC   r   rG   rG   rH   nested_width  s    z _CategoricalPlotter.nested_widthc                 C   s2  | j dkr| j| j }}n| j| j }}|dur:|| |durL|| | j}|sndd tt| jD }| j dkr|	t
t| j || n |t
t| j || | j dkr|jd |jdt| jd dd n&|jd |jdt| jd dd | jdur.|jd	| jd
 dS )z)Add descriptive labels to an Axes object.rL   Nc                 S   s   g | ]}d qS )r5   rG   rJ   r   rG   rG   rH   re     rN   z5_CategoricalPlotter.annotate_axes.<locals>.<listcomp>Frp   rq   rr   best)locr   )r2   r   r   
set_xlabel
set_ylabelr   r   rg   r9   
set_xticksrh   arangeset_xticklabels
set_yticksset_yticklabelsru   rv   rw   rx   ry   r   r?   r   )rC   rz   xlabelylabelr   rG   rG   rH   annotate_axes  s,    





z!_CategoricalPlotter.annotate_axesc              	   C   s2   t jddgdd| jd | j||d}|| dS )z3Add a dummy patch object so we can get legend data.r   r   )	linewidthr   	facecolorr  N)plt	Rectangler'  r   	add_patch)rC   rz   r*   r  rectrG   rG   rH   r     s    z#_CategoricalPlotter.add_legend_data)NNNNNNNN)r   r   r   r   r  r3   r   r   r  r   r  r  r&  r   rG   rG   rG   rH   r     s       
 N;

!r   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
_BoxPlotterc              	   C   sR   |  ||||||| | ||	|
 || _|| _|| _|d u rHtjd }|| _d S )Nlines.linewidth)r   r  r   r   	fliersizerS   rcParamsr'  )rC   r$   r%   r&   r,   rD   rZ   r2   r*   rY   r  r   r   r/  r'  rG   rG   rH   r7     s    
z_BoxPlotter.__init__c              	   C   s\  | j dk}i }dD ]}||d i ||< qt| jD ]\}}| jdu r|jdkrVq6tt|}|jdkrpq6|j	|f|d|g| j
d|}	| j| }
| |	|
| q6| j}t| jD ]\}}|s| || j| | |jdkrq| j| |k}tt|| }|jdkrq|||  }|j	|f|d|g| jd|}	| |	| j| | qq6dS )z,Use matplotlib to draw a boxplot on an Axes.rL   )boxwhiskercapmedianflierpropsNr   T)vertpatch_artist	positionswidths)r2   r<   	enumerater9   r   r   rh   r   r   r   r   rT   restyle_boxplotr  r   r   r  )rC   rz   kwsr7  r6  objr   
group_databox_dataartist_dictr*   r   j	hue_levelhue_maskr   rG   rG   rH   draw_boxplot  sR    





z_BoxPlotter.draw_boxplotc           	   	   C   s
  |d D ],}| t|d| j| jd | |d  q|d D ]*}| t| j| jdd | |d  q>|d	 D ](}| t| j| jd
 | |d  qr|d D ](}| t| j| jd
 | |d  q|d D ].}| t| jd| j| jd | |d  qdS )z6Take a drawn matplotlib boxplot and make it look nice.boxesg?)r(  zorderr   r'  r1  whiskers-)r*   r'  	linestyler2  capsr*   r'  r3  mediansr4  fliersr   )markerfacecolormarkermarkeredgecolor
markersizer5  N)updaterQ   r   r'  r/  )	rC   rA  r*   r6  r1  Zwhiskr3  medflyrG   rG   rH   r<  Z  s<    



z_BoxPlotter.restyle_boxplotc                 C   s,   |  || | | | jdkr(|  dS zMake the plot.r/   N)rE  r&  r2   invert_yaxis)rC   rz   Zboxplot_kwsrG   rG   rH   plotv  s    

z_BoxPlotter.plotN)r   r   r   r7   rE  r<  rX  rG   rG   rG   rH   r-    s   >r-  c                   @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	e
dd Zdd Zdd Zdd Zd#ddZdd Zd$ddZdd Zd d! Zd"S )%_ViolinPlotterc              	   C   s   |  ||||||| | ||| | |||	|
| || _|| _|| _|d urt|d|d|d|dgsd| d}t||| _	|r| j
d urt| j
dkrd}t||| _|d u rtjd	 }|| _d S )
Nquartr1  stickpointzInner style '' not recognizedr   z5There must be exactly two hue levels to use `split`.'r.  )r   r  estimate_densitiesgridsizer   r   r   r   r   innerr   rg   splitrS   r0  r'  )rC   r$   r%   r&   r,   rD   rZ   bwcutscale	scale_huer_  r   r`  ra  r   r2   r'  r*   rY   r  r   r[   rG   rG   rH   r7     s,    

z_ViolinPlotter.__init__c                 C   s|  | j du r4g }g }tt| j}tt| j}	nHdd | jD }dd | jD }t| jt| j f}
t|
}t|
}	t| jD ]\}}| jdu rt|}|j	dkr|
tg  |
tdg d||< d|	|< qnFt|j	dkr*|
t| |
tdg d||< d|	|< q| ||\}}| ||||}||}|
| |
| |j	||< | |	|< qt| j D ]\}}|j	s|| 
tg  || 
tdg d|||f< d|	||f< q| j| |k}t|| }|j	dkrP|| 
tg  || 
tdg d|||f< d|	||f< qnXt|j	dkr|| 
t| || 
tdg d|||f< d|	||f< q| ||\}}| ||||}||}|| 
| || 
| |j	|||f< | |	||f< qq|dkr,| ||	| n@|d	krB| | n*|d
kr\| ||| ntd| d|| _|| _dS )z1Find the support and density for all of the data.Nc                 S   s   g | ]}g qS rG   rG   r  rG   rG   rH   re     rN   z5_ViolinPlotter.estimate_densities.<locals>.<listcomp>c                 S   s   g | ]}g qS rG   rG   r  rG   rG   rH   re     rN   r         ?r   arear   countzscale method 'r]  )r   rh   r   rg   r9   r   r;  r   r   r   r   r  ri   fit_kdekde_supportevaluatemax
scale_areascale_widthscale_countr   supportdensity)rC   rb  rc  rd  re  r_  rp  rq  countsmax_densityr   r   r?  Zkde_datakdebw_usedZ	support_iZ	density_irB  rC  rD  Z
support_ijZ
density_ijrG   rG   rH   r^    s    











z!_ViolinPlotter.estimate_densitiesc                 C   s(   t ||}|j}||jdd }||fS )z<Estimate a KDE for a vector of data with flexible bandwidth.r   )ddof)r   factorstd)rC   r$   rb  rt  ru  rG   rG   rH   ri    s    
z_ViolinPlotter.fit_kdec                 C   s.   |  ||  }| ||  }t|||S )z(Define a grid of support for the violin.)rj   rl  rh   r   )rC   r$   rb  rc  r_  support_minsupport_maxrG   rG   rH   rj  +  s    z_ViolinPlotter.kde_supportc                 C   sx   | j du r,|D ]}|jdkr||  }qnHt|D ]>\}}|D ]0}|rV||  }n| }|jdkr@|| }q@q4dS )zScale the relative area under the KDE curve.

        This essentially preserves the "standard" KDE scaling, but the
        resulting maximum density will be 1 so that the curve can be
        properly multiplied by the violin width.

        Nr   )r   r   rl  r;  )rC   rq  rs  re  r   r   grouprl  rG   rG   rH   rm  1  s    


z_ViolinPlotter.scale_areac                 C   sF   | j du r"|D ]}||  }qn |D ]}|D ]}||  }q.q&dS )z,Scale each density curve to the same height.N)r   rl  )rC   rq  r   r{  rG   rG   rH   rn  G  s    
z_ViolinPlotter.scale_widthc           
      C   s   | j du rN| dkrd}qt||D ]$\}}||  }|||  9 }q&n|t|D ]r\}}t|D ]`\}}||  dkrd}qf|||f }|r|||   }	n||  }	||  }||	9 }qfqVdS )z7Scale each density curve by the number of observations.Nr   )r   rl  zipr;  )
rC   rq  rr  re  r   rh  r   r{  rB  ZscalerrG   rG   rH   ro  Q  s     
z_ViolinPlotter.scale_countc                 C   sB   | j d u s| js| jd S | jr*| jd S | jdt| j   S d S )Nr   )r   r   r   ra  rg   ra   rG   rG   rH   dwidthh  s
    

z_ViolinPlotter.dwidthc                 C   s|  | j dkr|jn|j}t| jD ]T\}}t| j| jd}| jdu rl| j	| | j
|  }}|jdkrjq n,|jdkr| }| }	| ||||	 q t| j| }
|||
|| j  |
|| j  fd| j| i| | jdu rq t|}| jdr
| ||| n`| jdr,| ||||| n>| jd	rN| ||||| n| jd
rv| ||| q | j}t| jD ]\}}| j	| | | j
| |  }}| j| |d< |s| || j| | |jdkrސq|nL|jdkr*| }| }	| jr
|	d }	|||  }| ||||	 q|| jrjt| j| }
|rh|||
|
|| j  fi | n|||
|| j  |
fi | | jdu rq|| j| |k}t|| }| jdr| |||||ddg|  n*| jd	r| |||||ddg|  |r$t| jd |kr$q|t|}| jdrJ| ||| n| jd
rr| ||| q|t| j|||   }
|||
|| j  |
|| j  fi | | jdu rq|| j| |k}t|| }| jdr| |||||   nx| jdr$| |||||||   nN| jd	rN| |||||||   n$| jd
r|| |||||   q|q dS )zDraw the violins onto `ax`.rL   r   r'  Nr   r   r(  r1  rZ  r[  r\  r   leftright)r2   fill_betweenxfill_betweenr;  r9   rQ   r   r'  r   rp  rq  r   itemdraw_single_observationrh   onesr_  r}  rT   r`  r   r   draw_box_linesdraw_quartilesdraw_stick_linesdraw_pointsr  r   r   ra  r   )rC   rz   Z	fill_funcr   r?  r=  rp  rq  valr   rv   Zviolin_datar   rB  rC  at_grouprD  rG   rG   rH   draw_violinsr  s    






z_ViolinPlotter.draw_violinsc                 C   sf   || j  }| jdkr<|j|| || g||g| j| jd n&|j||g|| || g| j| jd dS )z)Draw a line to mark a single observation.rL   rL  N)r}  r2   rX  r   r'  )rC   rz   r  Zat_quantrq  Zd_widthrG   rG   rH   r  !  s    


z&_ViolinPlotter.draw_single_observationc           
   
   C   s&  t |g d\}}}d||  }t |||| k }t |||| k }	| jdkr|j||g||	g| j| jd |j||g||g| jd | jd |j||dd| jt 	| jd d nd|j||	g||g| j| jd |j||g||g| jd | jd |j||dd| jt 	| jd d d	S )
z2Draw boxplot information at center of the density.   2   K         ?rL   )r'  r*   r]   whiter   )rG  r*   r   r   N)
rh   
percentilerj   rl  r2   rX  r'  r   r)   square)
rC   rz   r,   r   q25q50q75Zwhisker_limh1h2rG   rG   rH   r  /  sB    
z_ViolinPlotter.draw_box_linesFc           
   
   C   s   t |g d\}}}	| j||||||| j| jd gd d | j||||||| j| jd gd d | j|||	|||| j| jd gd d dS )z0Draw the quartiles as lines at width of density.r  r  r   )r'  dashesr]   N)rh   r  draw_to_densityr'  )
rC   rz   r,   rp  rq  r   ra  r  r  r  rG   rG   rH   r  Q  s    z_ViolinPlotter.draw_quartilesc                 C   sh   t t| jd | j| jd}tt|| }| jdkrP|j||fi | n|j||fi | dS )z?Draw individual observations as points at middle of the violin.r   )r   r*   r   rL   N)	rQ   rh   r  r'  r   r  rg   r2   r)   )rC   rz   r,   r   r=  rv   rG   rG   rH   r  _  s    
z_ViolinPlotter.draw_pointsc              
   C   s,   |D ]"}| j ||||||| jd d qdS )z;Draw individual observations as sticks at width of density.rq   )r'  N)r  r'  )rC   rz   r,   rp  rq  r   ra  r  rG   rG   rH   r  l  s    z_ViolinPlotter.draw_stick_linesc           
      K   s2  t t || }| j||  d }	| j|d< | jdkr|dkrd|j||	 |g||gfi | nN|dkr|j|||	 g||gfi | n$|j||	 ||	 g||gfi | nz|dkr|j||g||	 |gfi | nP|dkr
|j||g|||	 gfi | n$|j||g||	 ||	 gfi | dS )z=Draw a line orthogonal to the value axis at width of density.gGz?r*   rL   r  r  N)rh   argminabsr}  r   r2   rX  )
rC   rz   r   r  rp  rq  ra  r=  idxr   rG   rG   rH   r  s  s    

""&"
"z_ViolinPlotter.draw_to_densityc                 C   s*   |  | | | | jdkr&|  dS )zMake the violin plot.r/   N)r  r&  r2   rW  rC   rz   rG   rG   rH   rX    s    


z_ViolinPlotter.plotN)F)F)r   r   r   r7   r^  ri  rj  rm  rn  ro  r   r}  r  r  r  r  r  r  r  rX  rG   rG   rG   rH   rY  ~  s&   }

	 0"
 
rY  c                   @   s.   e Zd ZdZedd Zdd Zd	ddZdS )
_CategoricalStatPlotterTc                 C   s"   | j r| jt| j }n| j}|S )r  r  r  rG   rG   rH   r    s    z$_CategoricalStatPlotter.nested_widthc                 C   s  | j d u rg }g }n dd | jD }dd | jD }ddd| j }t||||d}t| jD ]N\}	}
| jd u rt||
i}| jd ur| j|	 |d< |||}|	||  |d ur|	|| d	 || d
 f q^| j D ]}| j|	 j
s$||	 	tj |d ur||	 	tjtjf q| j|	 |k}t||
| i}| jd urb| j|	 | |d< |||}||	 	||  |d ur||	 	|| d	 || d
 f qq^t|| _t|| _d S )Nc                 S   s   g | ]}g qS rG   rG   r  rG   rG   rH   re     rN   z>_CategoricalStatPlotter.estimate_statistic.<locals>.<listcomp>c                 S   s   g | ]}g qS rG   rG   r  rG   rG   rH   re     rN   r%   r$   r`   )n_bootseedr'   rj   rl  )r   r9   r2   r   r;  r   r   r   r   r   r   rh   nanr  	statisticconfint)rC   	estimatorerrorbarr  r  r  r  r   aggr   r?  dfresrC  rD  rG   rG   rH   estimate_statistic  s@    



$

*z*_CategoricalStatPlotter.estimate_statisticNc                 K   sj  |d ur| d| n| dtjd d  t|||D ]*\}\}	}
}| jdkr|j||g|	|
gfd|i| |d ur|j||d  ||d  g|	|	gfd|i| |j||d  ||d  g|
|
gfd|i| q8|j|	|
g||gfd|i| |d ur8|j|	|	g||d  ||d  gfd|i| |j|
|
g||d  ||d  gfd|i| q8d S )Nlwr.  ?rL   r*   r   )
setdefaultrS   r0  r|  r2   rX  )rC   rz   r  r  rT   errwidthcapsizer=  atZci_lowZci_highr*   rG   rG   rH   draw_confints  sP    
  

z%_CategoricalStatPlotter.draw_confints)NN)r   r   r   r3   r   r  r  r  rG   rG   rG   rH   r    s   
9 r  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )_BarPlotterc              
   C   sX   |  ||||||||
 | ||| | |||	| || _|| _|| _|| _|| _dS )Initialize the plotter.N)r   r  r  r   r   errcolorr  r  )rC   r$   r%   r&   r,   rD   rZ   r  r  r  r'   r  r2   r*   rY   r  r   r  r  r  r   rG   rG   rH   r7     s    z_BarPlotter.__init__c           
   	   C   s  | j dkr|jn|j}tt| j}| jdu r|||| j| jf| j	dd| | j
gt| }| ||| j|| j| j nt| jD ]\}}|| j|  }||| jdd|f | jf| j	| d|d| | jjr| jdd|f }	| j
gt| }| |||	|| j| j qdS )zDraw the bars onto `ax`.rL   Nr   )r*   align)r*   r  r  )r2   barbarhrh   r   rg   r  r   r   rT   r  r  r  r  r  r;  r   r  r  r   )
rC   rz   r=  ZbarfuncZbarpos	errcolorsrB  rC  offposr  rG   rG   rH   	draw_bars  sD    
	
z_BarPlotter.draw_barsc                 C   s,   |  || | | | jdkr(|  dS rV  )r  r&  r2   rW  )rC   rz   Zbar_kwsrG   rG   rH   rX  0  s    

z_BarPlotter.plotN)r   r   r   r7   r  rX  rG   rG   rG   rH   r    s   *r  c                   @   s4   e Zd ZdZdd Zedd Zdd Zdd	 Zd
S )_PointPlotterr	  c              
   C   s  |  ||||||||
 | ||d | |||	| |du rf|du rf|du rft d gt| j | _|du rz|durzd}|du r| jdurdt| j }t|tr|gt| j }|| _	t|tr|gt| j }|| _
|| _|| _|| _|| _|| _|| _dS )r  r   Nr   FTg?)r   r  r  r   rg   rT   r   rP   rI   markers
linestylesr   joinrd  r  r  r  )rC   r$   r%   r&   r,   rD   rZ   r  r  r  r'   r  r  r  r   r  rd  r2   r*   rY   r  r  r  rG   rG   rH   r7   <  s.    

z_PointPlotter.__init__c                 C   s>   | j r*td| j t| j}|| 8 }ntt| j}|S )z;Offsets relative to the center position for each hue level.r   )r   rh   r   rg   r   r   r   )rC   offsetrG   rG   rH   r  d  s
    z_PointPlotter.hue_offsetsc                 C   s  t t| j}tjd d | j }|d }t jt | d }| j	du r| j
r| jd }| jd }| jdkr|j| j||||d n|j|| j|||d | ||| j| j| j| j | jd }d	d
 | jD }	| jdkr| j| }
}n|| j }
}|j|
|||||	|	| jd nl| j}t| jD ]X\}}| jdd|f }|||  }|d }| j
r| j| }| j| }| jdkr|j||||||d n|j||||||d | jjr| jdd|f }| j| gt| }| j||||| j| j|d tt|}| j| }tjj| j| }| jdkr<|| }
}n
|| }
}tt|sdt jg|  }
}|j|
||||||||d	 q(dS )z*Draw the main data components of the plot.r.  r        ?r   Nr   r/   )r*   lsr  c                 S   s   g | ]}t jj|qS rG   )rS   rT   colorConverterto_rgbr  rG   rG   rH   re     rN   z-_PointPlotter.draw_points.<locals>.<listcomp>)r'  rP  r   r(  r   r  r   )r*   rG  r  r  )rG  )r  r(  r   r'  rP  r   rG  )rh   r   rg   r  rS   r0  rd  pir  r   r  rT   r  r2   rX  r  r  r  r  r  r)   r  r  r;  r   r   r   r  r  r  )rC   rz   Zpointposr  mewrR  r*   r  rP  rT   r$   r%   r   rB  rC  r  r  zr  r  Zn_pointsrG   rG   rH   r  n  s|    















z_PointPlotter.draw_pointsc                 C   s*   |  | | | | jdkr&|  dS rV  )r  r&  r2   rW  r  rG   rG   rH   rX    s    


z_PointPlotter.plotN)	r   r   r   r  r7   r   r  r  rX  rG   rG   rG   rH   r  8  s   (
	Wr  c                   @   s   e Zd ZdZdS )_CountPlotterFN)r   r   r   r3   rG   rG   rG   rH   r    s   r  c                   @   sZ   e Zd ZdddZdd Zdd Zdd	 Zg d
dddddfddZdddZdd Z	dS )
_LVPlotterTc              	   C   s  || _ || _|
| _g d}||v sFt|tsFd| d| d}t||| _|d u r^tjd }|| _	g d}||vrd| d| d}t||| _
|d	ks|d
krd| d}t||| _d
|  k rd	k sn d| d}t||| _|| _| ||||||| | ||	|
 d S )N)
proportiontukeytrustworthyfullzk_depth must be one of z or a number, but z was passed.r.  linearexponentialrg  zscale must be one of z, but r   r   zoutlier_prop z not in range (0, 1]ztrust_alpha z not in range (0, 1))r   r   r  rP   r   r   k_depthrS   r0  r'  rd  outlier_proptrust_alpha
showfliersr   r  )rC   r$   r%   r&   r,   rD   rZ   r2   r*   rY   r  r   r   r  r'  rd  r  r  r  Zk_depth_methodsr[   scalesrG   rG   rH   r7     s:    
z_LVPlotter.__init__c           
         sn  t   tdd   t    W d   n1 s<0    Y  t }| j}| jdkrrtt 	|d }n| jdkrtt 	|d }nv| jdkrtt 	|tt 	||  d }nF| jd	krd
t
d| jd
  d
  }tt 	|| d }n
t| j}|dk rd}dd t|ddD }dd t|ddD }dd t||D } fdd|D }	|	|fS )zQGet the number of data points and calculate `depth` of
        letter-value plot.zmode.use_inf_as_nullTNr  r   r  r]   r  r  r   c                 S   s    g | ]}d dd|d    qS )d   r   rq   rG   r   rG   rG   rH   re     rN   z+_LVPlotter._lv_box_ends.<locals>.<listcomp>r   c                 S   s   g | ]}d d|d   qS )r  rq   r   rG   r   rG   rG   rH   re     rN   c                 S   s   g | ]\}}||fqS rG   rG   )rJ   r   rB  rG   rG   rH   re     rN   c                    s   g | ]}t  |qS rG   )rh   r  )rJ   qr   rG   rH   re     rN   )rh   r   r   option_contextisnullrg   r  r  intlog2r   r  r   r|  )
rC   r   r{   prK   Z
point_confupperlowerZpercentile_endsbox_endsrG   r  rH   _lv_box_ends  s,    
.


&


z_LVPlotter._lv_box_endsc                 C   sn   d|d  }d| dd|  f}t ||}|t ||d k d  }|t ||d kd  }t ||fS )z2Find the outliers based on the letter value depth.rq   r   r  r   )rh   r  whereconcatenate)rC   r   rK   Zbox_edgeZ	perc_endsedgesZ	lower_outZ	upper_outrG   rG   rH   _lv_outliers"  s    z_LVPlotter._lv_outliersc                 C   s    dd dd dd d}|| S )Nc                 S   s   |d | S )Nrf  rG   r/   r   rK   rG   rG   rH   <lambda>-  rN   z-_LVPlotter._width_functions.<locals>.<lambda>c                 S   s   d| | d  S )Nr   r   rG   r  rG   rG   rH   r  .  rN   c                 S   s   dd| | d   |  S )Nr   r   rG   r  rG   rG   rH   r  /  rN   r  rG   )rC   Z
width_funcZwidth_functionsrG   rG   rH   _width_functions+  s
    z_LVPlotter._width_functions)g     ?g      ?g        r   Nc	           !   
      s\  |d u ri n|  }|d u r i n|  }|d u r4i n|  }t| j| jd}	|	 D ]\}
||
 qTtddd| jd}| D ]\}
||
 qtd| jd}| D ]\}
||
 q| jdk}|d	 t|}t	|d
krx|
|d |ddt|d |d d |d	 |d	 g}d  d  g}|rV|| }}n
|| }}|j||fi | n| |\}| | jdd fdd}fdd}tfddt|D }|t| }t|}g }| jr| |}tj|}|rR| d  d  g}||g}tt	|}|}n8| ||g}d  d  g}|}tt	|}|j||fi | t	|d	kr|j||fi | |dg}tjjd|}||dg}tjjd|}|d|  fddtt||D }t|fi |} | tt d
d	t	| |!|  d S )Nr~  z.15g?butt)r*   alphasolid_capstyler'  r   )rP  r*   rL   r   r   r   rJ  rI  r'  )r*   rJ  r'  r   c                 S   s   | d | d  S )Nr   r   rG   )brG   rG   rH   heightl  s    z"_LVPlotter._lvplot.<locals>.heightc                    s2   t j| | d  |d f|  |dd}|S )Nr   r   TfillPatchesr*  r$   r  r   rK   wr,  r  r:  rG   rH   vert_perc_boxp  s
    z)_LVPlotter._lvplot.<locals>.vert_perc_boxc                    s2   t j|d | | d  f || dd}|S )Nr   r   Tr  r  r  r  rG   rH   horz_perc_boxv  s
    z)_LVPlotter._lvplot.<locals>.horz_perc_boxc                    s    g | ]\}} ||qS rG   rG   rJ   r   r  )r  rK   r   rG   rH   re   }  s   z&_LVPlotter._lvplot.<locals>.<listcomp>)r   r   r   Znew_mapg333333?cmapc              	      s(   g | ] \}} |d  ||d qS )r   r   rG   r  )box_funcrK   r$   rG   rH   re     s   )"copyrQ   r   r'  rR   r  r2   rh   r   rg   rS  r>   rl  rX  r  r  rd  r  r;  r4  r  r  rS   rT   r  r  r)   LinearSegmentedColormap	from_listr|  r	   	set_arrayr   add_collection)!rC   r@  r9  r*   r:  rz   box_kws	flier_kwsline_kwsZbox_default_kwsrL   Zline_default_kwsZflier_default_kwsr7  ysxsxxyyr  r  r  Zw_arear%   Zoutliers	hex_colorZ	xs_medianZ	ys_medianZxs_outliersZys_outliersrd   r  rF  
collectionrG   )r  r  rK   r   r:  r$   rH   _lvplot2  s    





z_LVPlotter._lvplotc                 C   s  t | jD ]\}}| jdu rf|jdkr(q
t|}|jdkr<q
| j| }| j||g|| j||||d q
| j}	t | j	D ]\}
}|s| 
|| j|
 | |jdkrqv| j| |k}t|| }|jdkrqv| j|
 }||	|
  }| j||g|| j||||d qvq
|j| jdk| jdkd dS )z6Use matplotlib to draw a letter value plot on an Axes.Nr   )r9  r*   r:  rz   r   r  r  r/   rL   r   )r;  r9   r   r   r   rT   r	  r   r  r   r   r  r   r2   )rC   rz   r   r  r  r   r?  r@  r*   r   rB  rC  rD  r   rG   rG   rH   draw_letter_value_plot  sN    








z!_LVPlotter.draw_letter_value_plotc                 C   s0   |  |||| | | | jdkr,|  dS rV  )r
  r&  r2   rW  )rC   rz   r   r  r  rG   rG   rH   rX    s    

z_LVPlotter.plot)T)NNN)
r   r   r   r7   r  r  r  r	  r
  rX  rG   rG   rG   rH   r    s    
)&	
 	  
Ar  a*      .. note::
        This function always treats one of the variables as categorical and
        draws data at ordinal positions (0, 1, ... n) on the relevant axis,
        even when the data has a numeric or date type.

    See the :ref:`tutorial <categorical_tutorial>` for more information.    a<      .. note::
        By default, this function treats one of the variables as categorical
        and draws data at ordinal positions (0, 1, ... n) on the relevant axis.
        This can be disabled with the `native_scale` parameter.

        See the :ref:`tutorial <categorical_tutorial>` for more information.    z    x, y, hue : names of variables in ``data`` or vector data, optional
        Inputs for plotting long-form data. See examples for interpretation.    z    x, y, hue : names of variables in ``data``
        Inputs for plotting long-form data. See examples for interpretation.    z    data : DataFrame, array, or list of arrays, optional
        Dataset for plotting. If ``x`` and ``y`` are absent, this is
        interpreted as wide-form. Otherwise it is expected to be long-form.    z    data : DataFrame
        Long-form (tidy) dataset for plotting. Each column should correspond
        to a variable, and each row should correspond to an observation.    z    order, hue_order : lists of strings, optional
        Order to plot the categorical levels in; otherwise the levels are
        inferred from the data objects.    a~      estimator : string or callable that maps vector -> scalar, optional
        Statistical function to estimate within each categorical bin.
    errorbar : string, (string, number) tuple, callable or None
        Name of errorbar method (either "ci", "pi", "se", or "sd"), or a tuple
        with a method name and a level parameter, or a function that maps from a
        vector to a (min, max) interval, or None to hide errorbar.
    n_boot : int, optional
        Number of bootstrap samples used to compute confidence intervals.
    units : name of variable in ``data`` or vector data, optional
        Identifier of sampling units, which will be used to perform a
        multilevel bootstrap and account for repeated measures design.
    seed : int, numpy.random.Generator, or numpy.random.RandomState, optional
        Seed or random number generator for reproducible bootstrapping.    a$      orient : "v" | "h", optional
        Orientation of the plot (vertical or horizontal). This is usually
        inferred based on the type of the input variables, but it can be used
        to resolve ambiguity when both `x` and `y` are numeric or when
        plotting wide-form data.    z]    color : matplotlib color, optional
        Single color for the elements in the plot.    z    palette : palette name, list, or dict, optional
        Color palette that maps the hue variable. If the palette is a dictionary,
        keys should be names of levels and values should be matplotlib colors.    z    hue_norm : tuple or :class:`matplotlib.colors.Normalize` object
        Normalization in data units for colormap applied to the `hue`
        variable when it is numeric. Not relevant if `hue` is categorical.    a      saturation : float, optional
        Proportion of the original saturation to draw colors at. Large patches
        often look better with slightly desaturated colors, but set this to
        `1` if you want the plot colors to perfectly match the input color.    zN    capsize : float, optional
        Width of the "caps" on error bars./
    zS    errwidth : float, optional
        Thickness of error bar lines (and caps).    z    width : float, optional
        Width of a full element when not using hue nesting, or width of all the
        elements for one level of the major grouping variable.    z    dodge : bool, optional
        When hue nesting is used, whether elements should be shifted along the
        categorical axis.    za    linewidth : float, optional
        Width of the gray lines that frame the plot elements.    z    native_scale : bool, optional
        When True, numeric or datetime values on the categorical axis will maintain
        their original scaling rather than being converted to fixed indices.    z    formatter : callable, optional
        Function for converting categorical data into strings. Affects both grouping
        and tick labels.    a  legend : "auto", "brief", "full", or False
    How to draw the legend. If "brief", numeric `hue` and `size`
    variables will be represented with a sample of evenly spaced values.
    If "full", every group will get an entry in the legend. If "auto",
    choose between brief or full representation based on number of levels.
    If `False`, no legend data is added and no legend is drawn.
    zr    ax : matplotlib Axes, optional
        Axes object to draw the plot onto, otherwise uses the current Axes.    zY    ax : matplotlib Axes
        Returns the Axes object with the plot drawn onto it.    zH    boxplot : A traditional box-and-whisker plot with a similar API.    zL    violinplot : A combination of boxplot and kernel density estimation.    z    stripplot : A scatterplot where one variable is categorical. Can be used
                in conjunction with other plots to show each observation.    z    swarmplot : A categorical scatterplot where the points do not overlap. Can
                be used with other plots to show each observation.    zK    barplot : Show point estimates and confidence intervals using bars.    zL    countplot : Show the counts of observations in each categorical bin.    zk    pointplot : Show point estimates and confidence intervals using scatterplot
                glyphs.    zG    catplot : Combine a categorical plot with a :class:`FacetGrid`.    z<    boxenplot : An enhanced boxplot for larger datasets.    ) Zcategorical_narrativeZnew_categorical_narrativeZinput_paramsZstring_input_paramsZcategorical_dataZlong_form_dataZ
order_varsZstat_api_paramsr2   r*   rY   hue_normr  r  r  r   r   r'  native_scale	formatterr?   ax_inax_outr   r   r   r   r!   r"   r    r   r   r  r      r  )r$   r%   r&   rD   rZ   r2   r*   rY   r  r   r   r/  r'  whisrz   c                K   sR   t |||| ||||||	|
|||}|d u r2t }|t|d ||| |S )N)r  )r-  r)  gcarS  rQ   rX  )r,   r$   r%   r&   rD   rZ   r2   r*   rY   r  r   r   r/  r'  r  rz   kwargsplotterrG   rG   rH   r     s    r   av      Draw a box plot to show distributions with respect to categories.

    A box plot (or box-and-whisker plot) shows the distribution of quantitative
    data in a way that facilitates comparisons between variables or across
    levels of a categorical variable. The box shows the quartiles of the
    dataset while the whiskers extend to show the rest of the distribution,
    except for points that are determined to be "outliers" using a method
    that is a function of the inter-quartile range.

    {categorical_narrative}

    Parameters
    ----------
    {categorical_data}
    {input_params}
    {order_vars}
    {orient}
    {color}
    {palette}
    {saturation}
    {width}
    {dodge}
    fliersize : float, optional
        Size of the markers used to indicate outlier observations.
    {linewidth}
    whis : float, optional
        Maximum length of the plot whiskers as proportion of the
        interquartile range. Whiskers extend to the furthest datapoint
        within that range. More extreme points are marked as outliers.
    {ax_in}
    kwargs : key, value mappings
        Other keyword arguments are passed through to
        :meth:`matplotlib.axes.Axes.boxplot`.

    Returns
    -------
    {ax_out}

    See Also
    --------
    {violinplot}
    {stripplot}
    {swarmplot}
    {catplot}

    Examples
    --------

    .. include:: ../docstrings/boxplot.rst

    scottr   rg  r  r1  )r$   r%   r&   rD   rZ   rb  rc  rd  re  r_  r   r`  ra  r   r2   r'  r*   rY   r  rz   c                K   sL   t |||| ||||||	|
|||||||||}|d u r>t }|| |S r   )rY  r)  r  rX  )r,   r$   r%   r&   rD   rZ   rb  rc  rd  re  r_  r   r`  ra  r   r2   r'  r*   rY   r  rz   r  r  rG   rG   rH   r     s    

r   a9      Draw a combination of boxplot and kernel density estimate.

    A violin plot plays a similar role as a box and whisker plot. It shows the
    distribution of quantitative data across several levels of one (or more)
    categorical variables such that those distributions can be compared. Unlike
    a box plot, in which all of the plot components correspond to actual
    datapoints, the violin plot features a kernel density estimation of the
    underlying distribution.

    This can be an effective and attractive way to show multiple distributions
    of data at once, but keep in mind that the estimation procedure is
    influenced by the sample size, and violins for relatively small samples
    might look misleadingly smooth.

    {categorical_narrative}

    Parameters
    ----------
    {categorical_data}
    {input_params}
    {order_vars}
    bw : {{'scott', 'silverman', float}}, optional
        Either the name of a reference rule or the scale factor to use when
        computing the kernel bandwidth. The actual kernel size will be
        determined by multiplying the scale factor by the standard deviation of
        the data within each bin.
    cut : float, optional
        Distance, in units of bandwidth size, to extend the density past the
        extreme datapoints. Set to 0 to limit the violin range within the range
        of the observed data (i.e., to have the same effect as ``trim=True`` in
        ``ggplot``.
    scale : {{"area", "count", "width"}}, optional
        The method used to scale the width of each violin. If ``area``, each
        violin will have the same area. If ``count``, the width of the violins
        will be scaled by the number of observations in that bin. If ``width``,
        each violin will have the same width.
    scale_hue : bool, optional
        When nesting violins using a ``hue`` variable, this parameter
        determines whether the scaling is computed within each level of the
        major grouping variable (``scale_hue=True``) or across all the violins
        on the plot (``scale_hue=False``).
    gridsize : int, optional
        Number of points in the discrete grid used to compute the kernel
        density estimate.
    {width}
    inner : {{"box", "quartile", "point", "stick", None}}, optional
        Representation of the datapoints in the violin interior. If ``box``,
        draw a miniature boxplot. If ``quartiles``, draw the quartiles of the
        distribution.  If ``point`` or ``stick``, show each underlying
        datapoint. Using ``None`` will draw unadorned violins.
    split : bool, optional
        When using hue nesting with a variable that takes two levels, setting
        ``split`` to True will draw half of a violin for each level. This can
        make it easier to directly compare the distributions.
    {dodge}
    {orient}
    {linewidth}
    {color}
    {palette}
    {saturation}
    {ax_in}

    Returns
    -------
    {ax_out}

    See Also
    --------
    {boxplot}
    {stripplot}
    {swarmplot}
    {catplot}

    Examples
    --------

    .. include:: ../docstrings/violinplot.rst

    r  r  gy&1|?皙?)r$   r%   r&   rD   rZ   r2   r*   rY   r  r   r   r  r'  rd  r  r  r  rz   r   r  r  c                C   sN   t |||| ||||||	|
|||||||}|d u r:t }||||| |S r   )r  r)  r  rX  )r,   r$   r%   r&   rD   rZ   r2   r*   rY   r  r   r   r  r'  rd  r  r  r  rz   r   r  r  r  rG   rG   rH   r   _	  s    
r   a
      Draw an enhanced box plot for larger datasets.

    This style of plot was originally named a "letter value" plot because it
    shows a large number of quantiles that are defined as "letter values".  It
    is similar to a box plot in plotting a nonparametric representation of a
    distribution in which all features correspond to actual observations. By
    plotting more quantiles, it provides more information about the shape of
    the distribution, particularly in the tails. For a more extensive
    explanation, you can read the paper that introduced the plot:
    https://vita.had.co.nz/papers/letter-value-plot.html

    {categorical_narrative}

    Parameters
    ----------
    {categorical_data}
    {input_params}
    {order_vars}
    {orient}
    {color}
    {palette}
    {saturation}
    {width}
    {dodge}
    k_depth : {{"tukey", "proportion", "trustworthy", "full"}} or scalar
        The number of boxes, and by extension number of percentiles, to draw.
        All methods are detailed in Wickham's paper. Each makes different
        assumptions about the number of outliers and leverages different
        statistical properties. If "proportion", draw no more than
        `outlier_prop` extreme observations. If "full", draw `log(n)+1` boxes.
    {linewidth}
    scale : {{"exponential", "linear", "area"}}, optional
        Method to use for the width of the letter value boxes. All give similar
        results visually. "linear" reduces the width by a constant linear
        factor, "exponential" uses the proportion of data not covered, "area"
        is proportional to the percentage of data covered.
    outlier_prop : float, optional
        Proportion of data believed to be outliers. Must be in the range
        (0, 1]. Used to determine the number of boxes to plot when
        `k_depth="proportion"`.
    trust_alpha : float, optional
        Confidence level for a box to be plotted. Used to determine the
        number of boxes to plot when `k_depth="trustworthy"`. Must be in the
        range (0, 1).
    showfliers : bool, optional
        If False, suppress the plotting of outliers.
    {ax_in}
    box_kws: dict, optional
        Keyword arguments for the box artists; passed to
        :class:`matplotlib.patches.Rectangle`.
    line_kws: dict, optional
        Keyword arguments for the line denoting the median; passed to
        :meth:`matplotlib.axes.Axes.plot`.
    flier_kws: dict, optional
        Keyword arguments for the scatter denoting the outlier observations;
        passed to :meth:`matplotlib.axes.Axes.scatter`.

    Returns
    -------
    {ax_out}

    See Also
    --------
    {violinplot}
    {boxplot}
    {catplot}

    Examples
    --------

    .. include:: ../docstrings/boxenplot.rst

    r   r+   )r$   r%   r&   rD   rZ   r   r   r2   r*   rY   r   r   r'  r  r  r  r?   rz   c                K   s   t | t t ||d|d}|d u r,t }|j|jdksB|sT|j|j||d |	| |
|
|}||	|
|\}
}t|j||	|}	|j|
||d |dd |d|}|t|d	 ||d
 |j|||	||d || |j||jd |S )NFr,   r-   rD   r2   r3   r?   r4   rD   r  rY   rD   normrG  r]   r   r   )r   r   r'  r   r   r*   r   r   rb   )r#   get_semanticslocalsr)  r  r=   r>   rA   scale_categorical_attachr_   r\   r   r)   map_huer  rS  rQ   r   _add_axis_labelsr|   )r,   r$   r%   r&   rD   rZ   r   r   r2   r*   rY   r   r   r'  r  r  r  r?   rz   r  r  rG   rG   rH   r   	  sD    
	

r   a5      Draw a categorical scatterplot using jitter to reduce overplotting.

    A strip plot can be drawn on its own, but it is also a good complement
    to a box or violin plot in cases where you want to show all observations
    along with some representation of the underlying distribution.

    {new_categorical_narrative}

    Parameters
    ----------
    {input_params}
    {categorical_data}
    {order_vars}
    jitter : float, ``True``/``1`` is special-cased, optional
        Amount of jitter (only along the categorical axis) to apply. This
        can be useful when you have many points and they overlap, so that
        it is easier to see the distribution. You can specify the amount
        of jitter (half the width of the uniform random variable support),
        or just use ``True`` for a good default.
    dodge : bool, optional
        When using ``hue`` nesting, setting this to ``True`` will separate
        the strips for different hue levels along the categorical axis.
        Otherwise, the points for each level will be plotted on top of
        each other.
    {orient}
    {color}
    {palette}
    size : float, optional
        Radius of the markers, in points.
    edgecolor : matplotlib color, "gray" is special-cased, optional
        Color of the lines around each point. If you pass ``"gray"``, the
        brightness is determined by the color palette used for the body
        of the points.
    {linewidth}
    {native_scale}
    {formatter}
    {legend}
    {ax_in}
    kwargs : key, value mappings
        Other keyword arguments are passed through to
        :meth:`matplotlib.axes.Axes.scatter`.

    Returns
    -------
    {ax_out}

    See Also
    --------
    {swarmplot}
    {boxplot}
    {violinplot}
    {catplot}

    Examples
    --------

    .. include:: ../docstrings/stripplot.rst

    )r$   r%   r&   rD   rZ   r   r2   r*   rY   r   r   r'  r  r  r  r?   r   rz   c                K   s  t | t t ||d|d}|d u r,t }|j|jdksB|sT|j|j||d |	| |j
sh|S ||	|}|||	|\}	}t|j|||}|j|	||d |dd |d|
}
|d u r|
d	 }|t|
d
 |d |j|||||d || |j||jd |S )NFr  r4   r  r  rG  r]   r   r   r   )r   r'  r   r*   r   r   r   rb   )r#   r  r  r)  r  r=   r>   rA   r  r  r@   r_   r\   r   r)   r   r  rS  rQ   r   r!  r|   )r,   r$   r%   r&   rD   rZ   r   r2   r*   rY   r   r   r'  r  r  r  r?   r   rz   r  r  rG   rG   rH   r   8
  sJ    
	

r   a      Draw a categorical scatterplot with points adjusted to be non-overlapping.

    This function is similar to :func:`stripplot`, but the points are adjusted
    (only along the categorical axis) so that they don't overlap. This gives a
    better representation of the distribution of values, but it does not scale
    well to large numbers of observations. This style of plot is sometimes
    called a "beeswarm".

    A swarm plot can be drawn on its own, but it is also a good complement
    to a box or violin plot in cases where you want to show all observations
    along with some representation of the underlying distribution.

    {new_categorical_narrative}

    Parameters
    ----------
    {categorical_data}
    {input_params}
    {order_vars}
    dodge : bool, optional
        When using ``hue`` nesting, setting this to ``True`` will separate
        the strips for different hue levels along the categorical axis.
        Otherwise, the points for each level will be plotted in one swarm.
    {orient}
    {color}
    {palette}
    size : float, optional
        Radius of the markers, in points.
    edgecolor : matplotlib color, "gray" is special-cased, optional
        Color of the lines around each point. If you pass ``"gray"``, the
        brightness is determined by the color palette used for the body
        of the points.
    {linewidth}
    {native_scale}
    {formatter}
    {legend}
    {ax_in}
    kwargs : key, value mappings
        Other keyword arguments are passed through to
        :meth:`matplotlib.axes.Axes.scatter`.

    Returns
    -------
    {ax_out}

    See Also
    --------
    {boxplot}
    {violinplot}
    {stripplot}
    {catplot}

    Examples
    --------

    .. include:: ../docstrings/swarmplot.rst

    r   )ci_   i  z.26
deprecated)r$   r%   r&   rD   rZ   r  r  r  r'   r  r2   r*   rY   r  r   r  r  r  r   r#  rz   c                K   sf   t ||}|tu rd}t|||| ||||||	|
|||||||||}|d u rVt }||| |S )Nr   )r   _deprecate_cirg   r  r)  r  rX  )r,   r$   r%   r&   rD   rZ   r  r  r  r'   r  r2   r*   rY   r  r   r  r  r  r   r#  rz   r  r  rG   rG   rH   r!   
  s    	

r!   aP      Show point estimates and errors as rectangular bars.

    A bar plot represents an estimate of central tendency for a numeric
    variable with the height of each rectangle and provides some indication of
    the uncertainty around that estimate using error bars. Bar plots include 0
    in the quantitative axis range, and they are a good choice when 0 is a
    meaningful value for the quantitative variable, and you want to make
    comparisons against it.

    For datasets where 0 is not a meaningful value, a point plot will allow you
    to focus on differences between levels of one or more categorical
    variables.

    It is also important to keep in mind that a bar plot shows only the mean
    (or other estimator) value, but in many cases it may be more informative to
    show the distribution of values at each level of the categorical variables.
    In that case, other approaches such as a box or violin plot may be more
    appropriate.

    {categorical_narrative}

    Parameters
    ----------
    {categorical_data}
    {input_params}
    {order_vars}
    {stat_api_params}
    {orient}
    {color}
    {palette}
    {saturation}
    {width}
    errcolor : matplotlib color
        Color used for the error bar lines.
    {errwidth}
    {capsize}
    {dodge}
    {ax_in}
    kwargs : key, value mappings
        Other keyword arguments are passed through to
        :meth:`matplotlib.axes.Axes.bar`.

    Returns
    -------
    {ax_out}

    See Also
    --------
    {countplot}
    {pointplot}
    {catplot}

    Examples
    --------

    .. include:: ../docstrings/barplot.rst


    orI  )r$   r%   r&   rD   rZ   r  r  r  r'   r  r  r  r   r  rd  r2   r*   rY   r  r#  r  r  rz   c                C   s\   t ||}t|||| ||||||	|
|||||||||||}|d u rNt }|| |S r   )r   r&  r  r)  r  rX  )r,   r$   r%   r&   rD   rZ   r  r  r  r'   r  r  r  r   r  rd  r2   r*   rY   r  r#  r  r  rz   r  rG   rG   rH   r      s    


r    a      Show point estimates and errors using dot marks.

    A point plot represents an estimate of central tendency for a numeric
    variable by the position of the dot and provides some indication of the
    uncertainty around that estimate using error bars.

    Point plots can be more useful than bar plots for focusing comparisons
    between different levels of one or more categorical variables. They are
    particularly adept at showing interactions: how the relationship between
    levels of one categorical variable changes across levels of a second
    categorical variable. The lines that join each point from the same `hue`
    level allow interactions to be judged by differences in slope, which is
    easier for the eyes than comparing the heights of several groups of points
    or bars.

    It is important to keep in mind that a point plot shows only the mean (or
    other estimator) value, but in many cases it may be more informative to
    show the distribution of values at each level of the categorical variables.
    In that case, other approaches such as a box or violin plot may be more
    appropriate.

    {categorical_narrative}

    Parameters
    ----------
    {categorical_data}
    {input_params}
    {order_vars}
    {stat_api_params}
    markers : string or list of strings, optional
        Markers to use for each of the ``hue`` levels.
    linestyles : string or list of strings, optional
        Line styles to use for each of the ``hue`` levels.
    dodge : bool or float, optional
        Amount to separate the points for each level of the ``hue`` variable
        along the categorical axis.
    join : bool, optional
        If ``True``, lines will be drawn between point estimates at the same
        ``hue`` level.
    scale : float, optional
        Scale factor for the plot elements.
    {orient}
    {color}
    {palette}
    {errwidth}
    {capsize}
    label : string, optional
        Label to represent the plot in a legend, only relevant when not using `hue`.
    {ax_in}

    Returns
    -------
    {ax_out}

    See Also
    --------
    {barplot}
    {catplot}

    Examples
    --------

    .. include:: ../docstrings/pointplot.rst

    )r$   r%   r&   rD   rZ   r2   r*   rY   r  r   r   rz   c                K   s   d}d }d}d }d }d }d }d }|d u r:|d ur:d}|}n2|d u rT|d urTd}|}n|d url|d urlt dt|||| |||||||||||	|
||||}d|_|d u rt }||| |S )Nr   r   r/   rL   z'Cannot pass values for both `x` and `y`rh  )r   r  r   r)  r  rX  )r,   r$   r%   r&   rD   rZ   r2   r*   rY   r  r   r   rz   r  r  r  r  r'   r  r  r  r  r  rG   rG   rH   r"   f  s6    

r"   a      Show the counts of observations in each categorical bin using bars.

    A count plot can be thought of as a histogram across a categorical, instead
    of quantitative, variable. The basic API and options are identical to those
    for :func:`barplot`, so you can compare counts across nested variables.

    Note that the newer :func:`histplot` function offers more functionality, although
    its default behavior is somewhat different.

    {categorical_narrative}

    Parameters
    ----------
    {categorical_data}
    {input_params}
    {order_vars}
    {orient}
    {color}
    {palette}
    {saturation}
    {dodge}
    {ax_in}
    kwargs : key, value mappings
        Other keyword arguments are passed through to
        :meth:`matplotlib.axes.Axes.bar`.

    Returns
    -------
    {ax_out}

    See Also
    --------
    {barplot}
    {catplot}

    Examples
    --------

    .. include:: ../docstrings/countplot.rst

    strip)r$   r%   r&   r   r   col_wrapr  r  r  r'   r  rD   rZ   	row_order	col_orderr  aspectkindr  r  r2   r*   rY   r  r?   
legend_outsharexshareymargin_titles	facet_kwsr#  c          4      K   sn  zt  |d  }!W n& ty8   d| d}"t|"Y n0 d| v rdd| d}#t|#t | d ddg}$||$v r|t| tt	 ||d|d	}%d
D ].}&|&|%j
v r|%j
|& d u rd|& d|%j
|&< q|%jj|%j
d} | jd d | j  f } |%j
dd }'|%j
dd }(|d u ri }tf | |(|'|||||||d
|})|%j}*|r\|%j|%j dkrn|%j|%j||d |%|) |*s|)S |%||}|%|||\}}|%j|||d |d u r|d u rd}|dkrD| dd}+| dd},| dd}-|  }.|.dd |.d|.ddd  |.dd  |%j|+|,||-|.d! n|dkr| dd},| dd}-| d"d#}/|  }.|.dd |.d|.ddd  |.dd d u rt|.d d$ |.d< |%j|,||-|/|.d% |)j j!D ]}0|%j"|0|%jd& q|)#|%j
d'd |%j
d(d  |)$  |)%  |)j j!D ]}0|)&|0 d |0_'q2|rx|d urx||||fvrx|)j(||d) |)S |du rd*| d+}"t|"|d urd,| d+}"t|"|d-kr|d u r|d ur||d.  }1}2}n.|d u r|d ur||d/  }1}2}ntd0n
|| }1}2t)t*t+t,t-t.d1| }3t/ }%|3j0|%_0|%1|1|2|| ||| |d us|rx|%j2d/ks|r|%j2d.kr|%j3}nd|d u r|d u rd2}#|s|%j2d/krt|#4d3d't |s|%j2d.krt|#4d4d(t |%j5}|%6||d5 |d6ks|d ur$|%j7}|d u r2i n|}|j8| |||||||||||dd7 t9|||||d8}.|.8|  |d9v rt:;||}|.j8|||	|
|d: tf i |})|)j<|!f|||d;|. |%j2d.kr|)#|%j=|%j> n|)#|%j>|%j= |d-kr,|d u r|)j#d-d< |d u r,|)j#d-d= |rj|d urj||||fvrjt?t@t:jA|}|)j(||d) |)S )>NrX  zPlot kind 'z' is not recognizedrz   zXcatplot is a figure-level function and does not accept target axes. You may wish to try r(  swarmFr  )r   r   r   r0   r   r   )
r,   r   r   r)  r*  r+  r  r/  r0  r,  r4   r  r  C0r   Tr   r   r   rG  r]   r   r   r  r   r'  r   r  r   r  r   r"  rb   r$   r%   )r   label_orderz+native_scale not yet implemented for `kind=`z(formatter not yet implemented for `kind=rh  r/   rL   z/Either `x` or `y` must be None for kind='count')r1  violinZboxenr  r\  rh  zSetting `{}=False` with `color=None` may cause different levels of the `{}` variable to share colors. This will change in a future version.r/  r0  r   r\  )r,   r   r   r*  r+  r)  r  r,  r/  r0  r.  r1  dropna)rD   rZ   r2   r*   rY   )r  r\  )r  r  r  r'   r  r(   )x_var)y_var)Bglobalsr  r   rV   rW   UserWarningr<   r   r  r  r-   r9   r:   r  r1   
duplicatedr>   r   r@   r=   rA   r  r  r_   r\   r   r  r  r   rh   sqrtr   axesflatr|   set_axis_labels
set_titlestight_layout_update_legend_datalegend_
add_legendr-  rY  r  r  r  r  r   r3   r   r2   r   formatr   r  rT   rS  rQ   r   r&  map_dataframer   r   r   r   to_utf8)4r,   r$   r%   r&   r   r   r)  r  r  r  r'   r  rD   rZ   r*  r+  r  r,  r-  r  r  r2   r*   rY   r  r?   r.  r/  r0  r1  r2  r#  r  Z	plot_funcr   r[   Zrefactored_kindsr  r   col_namerow_namer  r@   r   r   r   r   r   rz   x_y_Zplotter_classrG   rG   rH   r     s`   






	

 










 r   a(      Figure-level interface for drawing categorical plots onto a FacetGrid.

    This function provides access to several axes-level functions that
    show the relationship between a numerical and one or more categorical
    variables using one of several visual representations. The `kind`
    parameter selects the underlying axes-level function to use:

    Categorical scatterplots:

    - :func:`stripplot` (with `kind="strip"`; the default)
    - :func:`swarmplot` (with `kind="swarm"`)

    Categorical distribution plots:

    - :func:`boxplot` (with `kind="box"`)
    - :func:`violinplot` (with `kind="violin"`)
    - :func:`boxenplot` (with `kind="boxen"`)

    Categorical estimate plots:

    - :func:`pointplot` (with `kind="point"`)
    - :func:`barplot` (with `kind="bar"`)
    - :func:`countplot` (with `kind="count"`)

    Extra keyword arguments are passed to the underlying function, so you
    should refer to the documentation for each to see kind-specific options.

    Note that unlike when using the axes-level functions directly, data must be
    passed in a long-form DataFrame with variables specified by passing strings
    to `x`, `y`, `hue`, etc.

    {categorical_narrative}

    After plotting, the :class:`FacetGrid` with the plot is returned and can
    be used directly to tweak supporting plot details or add other layers.

    Parameters
    ----------
    {long_form_data}
    {string_input_params}
    row, col : names of variables in `data`, optional
        Categorical variables that will determine the faceting of the grid.
    {col_wrap}
    {stat_api_params}
    {order_vars}
    row_order, col_order : lists of strings, optional
        Order to organize the rows and/or columns of the grid in, otherwise the
        orders are inferred from the data objects.
    {height}
    {aspect}
    kind : str, optional
        The kind of plot to draw, corresponds to the name of a categorical
        axes-level plotting function. Options are: "strip", "swarm", "box", "violin",
        "boxen", "point", "bar", or "count".
    {native_scale}
    {formatter}
    {orient}
    {color}
    {palette}
    {hue_norm}
    legend : str or bool, optional
        Set to `False` to disable the legend. With `strip` or `swarm` plots,
        this also accepts a string, as described in the axes-level docstrings.
    {legend_out}
    {share_xy}
    {margin_titles}
    facet_kws : dict, optional
        Dictionary of other keyword arguments to pass to :class:`FacetGrid`.
    kwargs : key, value pairings
        Other keyword arguments are passed through to the underlying plotting
        function.

    Returns
    -------
    g : :class:`FacetGrid`
        Returns the :class:`FacetGrid` object with the plot on it for further
        tweaking.

    Examples
    --------

    .. include:: ../docstrings/catplot.rst

    c                   @   sL   e Zd ZdZdddZdd Zd	d
 Zdd Zdd Zdd Z	dddZ
dS )r   z6Modifies a scatterplot artist to show a beeswarm plot.rL   r   r  c                 C   s   || _ || _|| _d S r   )r2   r   r   )rC   r2   r   r   rG   rG   rH   r7     s    zBeeswarm.__init__c                 C   s  |j }|jj}| }| jdkr$dnd}||dd|f< |j\}}|j|}	| jdkrl|	ddddgf }	| }
|
j	dkrt
|
|	jd }
|  }t
|
| d |d  }t
j|	|f }	t
|	dddf }|	| }t
|}| |||< | jdkr|ddddgf }n|ddddf }|j |j\}}ddd	| j }t|d
| d dk}| jdkr| j|||d n| j|||d | jdkr|t
j||f  n|t
j||f  dS )z?Swarm `points`, a PathCollection, around the `center` position.r/   r   r   Nr   H   r%   r$   )r/   rL   rn   rd  log)	log_scale)r?  r   dpir   r2   Tr   	transform	get_sizesr   rh   repeatr   get_linewidthr  r>  c_argsort
empty_liker   invertedrt   add_guttersset_offsets)rC   r   r   rz   rQ  Zorig_xy_dataZcat_idxZorig_x_dataZorig_y_dataZorig_xysizesedgeradiisorterorig_xyrZnew_xyrZnew_xyZ
new_x_dataZ
new_y_dataZ
swarm_axisrP  rG   rG   rH   __call__!  s>    



zBeeswarm.__call__c           	      C   s   |d }t |d }|dd D ]^}| ||}| ||}t |dddf | }|t | }| ||}t ||g}q"|S )z.Adjust x position of points to avoid overlaps.)r   r   r   r   N)rh   
atleast_2dcould_overlapposition_candidatesr  rX  first_non_overlapping_candidatevstack)	rC   ra  Zmidliner3  xyr_i	neighbors
candidatesr   Z	new_xyr_irG   rG   rH   r   _  s    zBeeswarm.beeswarmc           
      C   sZ   |\}}}g }t |D ].}|\}}}	|| ||	 k r@|| q qFqt|ddd S )zAReturn a list of all swarm points that could overlap with target.Nr  )reversedr   rh   r  )
rC   rh  r3  r   y_ir_iri  Zxyr_jy_jr_jrG   rG   rH   rd    s    

zBeeswarm.could_overlapc                 C   s   |g}|\}}}d}|D ]z\}}	}
||	 }t t||
 d |d  dd }|| ||f|| ||f }}|rz||g}n||g}|| | }qt |S )z@Return a list of coordinates that might be valid by adjusting x.Tr   r   g?)rh   r>  rl  extendr  )rC   rh  ri  rj  x_irl  rm  Z
left_firstx_jrn  ro  dydxclcrZnew_candidatesrG   rG   rH   re    s    
$

zBeeswarm.position_candidatesc                 C   s   t |dkr|d S |dddf }|dddf }|dddf }|D ]Z}|\}}}	|| }
|| }t|
t| }t||	 }t||k}|rH|  S qHtddS )z>Find the first candidate that does not overlap with the swarm.r   Nr   r   z<No non-overlapping candidates found. This should not happen.)rg   rh   r  allr  )rC   rj  ri  Zneighbors_xZneighbors_yZneighbors_rrh  rq  rl  rm  rt  rs  Zsq_distancesZ
sep_neededZgood_candidaterG   rG   rH   rf    s"    

z(Beeswarm.first_non_overlapping_candidateFc                 C   s   | j d }|r"dt||  }n|| }||k }| rB|||< |rZdt||  }n|| }||k}| rz|||< ||  t| }	|	| jkrd|	}
t	|
t
 |S )z2Stop points from extending beyond their territory.r   r   zi{:.1%} of the points cannot be placed; you may want to decrease the size of the markers or use stripplot.)r   rh   log10r   sumrg   r   rG  rV   rW   r<  )rC   r   r   rP  
half_widthZ
low_gutterZoff_lowZhigh_gutterZoff_highZgutter_propr[   rG   rG   rH   r[    s*    

zBeeswarm.add_guttersN)rL   r   r  )F)r   r   r   __doc__r7   rb  r   rd  re  rf  r[  rG   rG   rG   rH   r     s   
> !r   )N)N)N)N)N)N)N)N)N)Mtextwrapr   numbersr   rV   colorsysr   	functoolsr   numpyrh   pandasr   scipy.statsr   	_no_scipyImportErrorZexternal.kde
matplotlibrS   matplotlib.collectionsr	   matplotlib.patchespatchesr  matplotlib.pyplotpyplotr)  Zseaborn._oldcorer
   r   r   Zseaborn.relationalr   seabornr   Zseaborn.utilsr   r   r   r   Zseaborn._statisticsr   Zseaborn.palettesr   r   r   r   seaborn.axisgridr   r   __all__r#   r   r   r-  rY  r  r  r  r  r  rQ   Z_categorical_docsrS  r   rG  r{  r   r   r   r   r!   r    r"   r   r   rG   rG   rG   rH   <module>   sn  

  t  js    bE   4	
  +
 


37 


OS 
IM 

;;? 
=:> 



;? 



AE 

()- 



  TW