
    eCi                   b   S SK Jr  S SKrS SKrS SKJr  S SKJr  S SKJrJ	r	J
r
  S SKJr  S SKJr  S SKrS SKrS SKrS SKJr  S S	KJrJr  S S
KJrJrJrJrJrJr   " S S5      r  " S S\ 5      r! " S S\ 5      r" " S S\ 5      r# " S S5      r$ " S S\5      r%SS jr&SS jr'S r(S r)SS jr*g)    )annotationsNcopy)
UserString)IterableSequenceMapping)Number)datetime)PlotData)QUAL_PALETTEScolor_palette)_check_argument_version_predates
desaturatelocator_to_legend_entriesget_color_cycle	remove_nac                  H    \ rS rSr% SrSrS\S'   SrSrS r	S r
S rS	 rS
rg)SemanticMapping   z6Base class for mapping data values to plot attributes.Nz
str | Nonemap_typec                    Xl         g Nplotter)selfr   s     G/home/james-whalen/.local/lib/python3.13/site-packages/seaborn/_base.py__init__SemanticMapping.__init__+   s	         c                    Sn[        U5      [        U5      :  af  SR                  SU S[        U5       S3S[        U5       S3S/5      n[        U[        R                  " U5      5       VVs/ s H  u  pVUPM	     nnnOV[        U5      [        U5      :  a>  SR                  S	U S
[        U5       S3S[        U5       S3/5      nUS[        U5       nU(       a  [
        R                  " U[        SS9  U$ s  snnf )z/Input check when values are provided as a list.  z
The z list has fewer values ()zthan needed (z) and will cycle, which mayz produce an uninterpretable plot.The z list has more values (z), which may not be intended.N   
stacklevel)lenjoinzip	itertoolscyclewarningswarnUserWarning)r   levelsvaluesvariablemessage_xs          r   _check_list_length"SemanticMapping._check_list_length4   s     v;V$hh
":3v;-qIF},GH2  G
 %(	0G$HI$HDAa$HFIF[3v;&hhxj 7F}AFF},IJ  G LS[)FMM';1= Js   /C:c                     U R                   U   $ )z)Apply the mapping to a single data value.lookup_table)r   keys     r   _lookup_singleSemanticMapping._lookup_singleL   s      %%r!   c                    [        U[        [        R                  [        R
                  45      (       a&  U Vs/ s H  o@R                  " U/UQ70 UD6PM     sn$ U R                  " U/UQ70 UD6$ s  snf )z-Get the attribute(s) values for the data key.)
isinstancelistnpndarraypdSeriesr>   )r   r=   argskwargsks        r   __call__SemanticMapping.__call__P   sg    cD"**bii899EHIS'';D;F;SII&&s<T<V<< Js   A1r   )__name__
__module____qualname____firstlineno____doc__r   __annotations__r2   r<   r   r8   r>   rJ   __static_attributes__ r!   r   r   r      s3    @
  Hj F L0&=r!   r   c                  V   ^  \ rS rSrSrSrSrSr S
U 4S jjrS r	S r
S rS rS	rU =r$ )
HueMappingX   z9Mapping that sets artist colors according to data values.Nc                  > [         TU ]  U5        UR                  R                  S[        R
                  " [        S95      n[        U[        R                  5      (       a'  Sn[        R                  " USS9  UR                  5       nUR                  5       R                  5       (       a  Ub  Sn[        R                  " USS9  ggU R                  X$UR                   UR"                  S   5      nUS:X  a,  [        R$                  " U5      nU R'                  XbU5      u  ppKO>US	:X  a  S=pU R)                  XbU5      u  pO S=pU R)                  [+        U5      X#5      u  pXPl        Xl        Xl        X l        Xl        X@l        Xl        g)
zoMap the levels of the `hue` variable to distinct colors.

Parameters
----------
# TODO add generic parameters

huedtypez|Numpy array is not a supported type for `palette`. Please convert your palette to a list. This will become an error in v0.14   r(   Nz?Ignoring `palette` because no `hue` variable has been assigned.numericcategorical)superr   	plot_datagetrE   rF   floatrA   rC   rD   r/   r0   tolistisnaallinfer_map_typeinput_format	var_types
to_numericnumeric_mappingcategorical_mappingrB   
saturationr   r<   paletter2   normcmap)r   r   rl   orderrm   rk   datamsgr   r2   r<   rn   	__class__s               r   r   HueMapping.__init__c   ss    	!  $$UBIIE,BCgrzz**5 
 MM#!,nn&G99;??"Wca0 #
 **w33W5F5Fu5MH 9$}}T*373G3G440dD ]*""'+'?'?5($ #"'+'?'? J($ )O$M ,"L KIIr!   c                    U R                   U   nU R                  S:  a  [        X R                  5      nU$ ! [         a    U R                  c   g U R                  U5      n[        R                  R                  U5      (       a  [        R                  nU R                  U5      n N! [         a*  n[        R                  " U5      (       a  Sn SnA NUeSnAff = ff = f)z@Get the color for a single value, using colormap to interpolate.N)r   r   r   r      )r<   KeyErrorrm   rC   ma	is_maskednanrn   	TypeErrorisnanrk   r   )r   r=   valuenormederrs        r   r>   HueMapping._lookup_single   s    	*%%c*E. ??Quoo6E3  	*yy  $
*3 55??6**VVF		&)  88C==(EI		*s:   8 C"B*#AC"*
C4CC"CCC"c                    U[         ;   a  SnU$ Ub  SnU$ [        U[        [        45      (       a  SnU$ US:X  a  SnU$ UnU$ )z'Determine how to implement the mapping.r]   r\   wide)r   rA   dictrB   )r   rl   rm   rf   var_typer   s         r   re   HueMapping.infer_map_type   sk    m#$H   H  $..$H  V#$H   Hr!   c                   [        X5      n[        U5      n[        U[        5      (       aH  [	        U5      [	        U5      -
  n[        U5      (       a  Sn[        UR                  U5      5      eUnXH4$ Uc1  U[        [        5       5      ::  a  [        SU5      n	O@[        SU5      n	O3[        U[        5      (       a  U R                  XBS5      n	O[        X%5      n	[        [        XI5      5      nXH4$ )z5Determine colors when the hue mapping is categorical.z*The palette dictionary is missing keys: {}Nhuslrl   )categorical_orderr*   rA   r   setany
ValueErrorformatr   r   rB   r8   r,   )
r   rp   rl   ro   r2   n_colorsmissingr~   r<   colorss
             r   rj   HueMapping.categorical_mapping   s     #4/v; gt$$&kCL0G7||B G!455"L  ## s?#455*4:F*68<FGT**00)L&w9F 34L##r!   c           
        [        U[        5      (       ab  [        [        U5      5      n[        U5       Vs/ s H  oRU   PM	     nn[        R
                  R                  U5      nUR                  5       nGO][        [        R                  " [        UR                  5       5      5      5      nUc  SOUn[        U[        R
                  R                  5      (       a  UnO
[        USS9nUc  [        R
                  R                  5       nOi[        U[        5      (       a  [        R
                  R                  " U6 nO6[        U[        R
                  R                  5      (       d  Sn	[!        U	5      eUR#                  5       (       d*  U" [        R$                  " UR'                  5       5      5        [        [)        XG" U" U5      5      5      5      nXHX74$ s  snf )z7Determine colors when the hue variable is quantitative.zch:T)as_cmapz6``hue_norm`` must be None, tuple, or Normalize object.)rA   r   rB   sortedmplr   ListedColormapr   rC   sortr   uniqueColormapr   	Normalizetupler   scaledasarraydropnar,   )
r   rp   rl   rm   r2   rI   r   rn   r<   r~   s
             r   ri   HueMapping.numeric_mapping   sZ   gt$$ &/*F*0/:/Qaj/F:::,,V4D"<<>L
 "'')DKKM":;<F  'eGG'3::#6#677$Wd; |zz++-D%((zz++T2cjj&:&:;;N o%;;==RZZ./FDf,> ?@LT//E ;s   G)rn   r2   r<   r   rm   rl   rk   NNNru   )rL   rM   rN   rO   rP   rl   rm   rn   r   r>   re   rj   ri   rR   __classcell__rr   s   @r   rU   rU   X   sB    CG D D HIHT@ $D)0 )0r!   rU   c                  N   ^  \ rS rSrSrSr S
U 4S jjrS rS rS r	S r
S	rU =r$ )SizeMappingi*  z8Mapping that sets artist sizes according to data values.Nc                  > [         T
U ]  U5        UR                  R                  S[        R
                  " [        S95      nUR                  5       R                  5       (       a  U R                  XBUR                  S   5      nUS:X  a  U R                  XRU5      u  pxpIO<US:X  a  U R                  XRU5      u  pxSn	OU R                  [        U5      X#5      u  pxSn	X`l        Xpl        X@l        X l        Xl        Xl        gg)zpMap the levels of the `size` variable to distinct values.

Parameters
----------
# TODO add generic parameters

sizerY   r\   r]   N)r^   r   r_   r`   rE   rF   ra   notnar   re   rg   ri   rj   rB   r   r2   rm   sizes
size_ranger<   )r   r   r   ro   rm   rp   r   r2   r<   r   rr   s             r   r   SizeMapping.__init__/  s    	!  $$VRYYU-CD::<**W..v6H 9$9=9M9M:6dJ ]*'+'?'?($ "
 (,'?'? J($
 "
$M KIJ(O ,Q r!   c                V    Ub  SnU$ [        U[        [        45      (       a  SnU$ UnU$ )Nr\   r]   )rA   r   rB   )r   rm   r   r   r   s        r   re   SizeMapping.infer_map_typeg  s?     H  d|,,$H   Hr!   c                8    U R                   U   nU$ ! [         a|    U R                  U5      n[        R                  R                  U5      (       a  [        R                  nU R                  S   U[        R                  " U R                  5      -  -   n U$ f = f)Nr   )	r<   rv   rm   rC   rw   rx   ry   r   ptp)r   r=   r|   r}   s       r   r>   SizeMapping._lookup_singler  s    	J%%c*E   	JYYs^Fuuv&&OOA&"&&2I)IIE	Js    BBBc                   [        X5      n[        U[        5      (       aJ  [        U5      [        U5      -
  n[	        U5      (       a  SU 3n[        U5      eUR                  5       nXG4$ [        U[        5      (       a)  U R                  XBS5      n[        [        XB5      5      nXG4$ [        U[        5      (       a  [        U5      S:w  a  Sn[        U5      eO)Ub  SU 3n[        U5      eU R                  R                  n[        R                  " / UQ[        U5      P76 S S S2   n[        [        XB5      5      nXG4$ )Nz(Missing sizes for the following levels: r      'A `sizes` tuple must have only 2 values"Value for `sizes` not understood: )r   rA   r   r   r   r   r   rB   r8   r,   r   r*   r   _default_size_rangerC   linspace)r   rp   r   ro   r2   r   r~   r<   s           r   rj   SizeMapping.categorical_mapping}  s?   "4/eT"" &kCJ.G7||@	J o% ::<LZ ##W t$$ ++F7CEF 23LN ##G %'' u:?CC$S/) # ":5'B o% 88 KK44F4TrT:EF 23L##r!   c                   [        U[        5      (       aO  [        [        R                  " [        U5      5      5      nUR                  5       n[        U5      [        U5      4nO[        [        R                  " [        UR                  5       5      5      5      n[        U[        5      (       a  [        U5      S:w  a  Sn[        U5      eUnO)Ub  SU 3n[        U5      eU R                  R                  nUc  [        R                   R#                  5       nOw[        U[        5      (       a  [        R                   R"                  " U6 nOD[        U[        R                   R"                  5      (       d  SU 3n[        U5      e[%        U5      nSUl        UR)                  5       (       d  U" U5        U" U5      n[        U[        5      (       a  Un	O!Uu  pXX-
  -  -   n[        [+        XB5      5      n	XIX64$ )Nr   r   r   z0Value for size `norm` parameter not understood: T)rA   r   rB   rC   r   r3   minmaxr   r   r   r*   r   r   r   r   r   r   r   clipr   r,   )r   rp   r   rm   r2   size_valuesr   r~   sizes_scaledr<   lohis               r   ri   SizeMapping.numeric_mapping  s   eT"" "''$u+./F,,.K[)3{+;;J
 "'')DKKM":;<F%'' u:?CC$S/)"
":5'B o% "\\==
 <::'')De$$::''.DD#**"6"677DTFKCS/! :D 	 {{}}L F| eT"" LFB11EF 23LT55r!   )r2   r<   r   rm   r   r   NNN)rL   rM   rN   rO   rP   rm   r   re   r>   rj   ri   rR   r   r   s   @r   r   r   *  s2    BD 596-p		8$tM6 M6r!   r   c                  D   ^  \ rS rSrSrSrSU 4S jjrS	S jrS rSr	U =r
$ )
StyleMappingi  z8Mapping that sets artist style according to data values.r]   c           	       > [         TU ]  U5        UR                  R                  S[        R
                  " [        S95      nUR                  5       R                  5       (       Ga  [        U5      S:X  a  [        U5      n[        XT5      nU R                  X&[        [        U5      5      S5      nU R                  X6[        [        U5      5      S5      n0 n/ nUR!                  5        H  u  p[#        U
[$        R&                  R(                  5      (       d  [$        R&                  R)                  U
5      n
U
R+                  5       R-                  U
R/                  5       5      Xy'   UR1                  U
R3                  5       5        M     [        U5      (       a  [5        U5      (       d  Sn[7        U5      e0 nU H2  n0 X'   U(       a  X-   X   S'   X}   X   S'   U(       d  M)  X=   X   S'   M4     X`l        Xl        g	g	)
zqMap the levels of the `style` variable to distinct values.

Parameters
----------
# TODO add generic parameters

stylerY   r   markersdashesz+Filled and line art markers cannot be mixedmarkerpathN)r^   r   r_   r`   rE   rF   ra   r   r   variable_typerB   r   _map_attributesunique_markersr*   unique_dashesitemsrA   r   r   MarkerStyleget_pathtransformedget_transformappend	is_filledrd   r   r2   r<   )r   r   r   r   ro   rp   r2   pathsfilled_markersrI   mr~   r<   r=   rr   s                 r   r   StyleMapping.__init__  s    	!  $$Wbiie.DE::< T"j0Dz 't3F**F!<iG ))c&k :HF
 EN!!S[[%<%<==//2A::<33AOO4EF%%akkm4	 ( >""3~+>+>C o%L$&!29,L%h/05
L%f-628+L%h/  !K ,Y r!   c                R    Uc  U R                   U   nU$ U R                   U   U   nU$ )z(Get attribute(s) for a given data point.r;   )r   r=   attrr|   s       r   r>   StyleMapping._lookup_singleG  s:    <%%c*E  %%c*40Er!   c                   USL a  [        [        X#5      5      nU$ [        U[         5      (       a5  [        U5      [        U5      -
  nU(       a  SU SU 3n[	        U5      eUnU$ [        U[
        5      (       a(  U R                  X!U5      n[        [        X!5      5      nU$ U(       a  SU SU 3n[	        U5      e0 nU$ )z5Handle the specification for a given style attribute.TzThese `z` levels are missing values: zThis `z` argument was not understood: )r   r,   rA   r   r   r   r8   )r   argr2   defaultsr   r<   r   r~   s           r   r   StyleMapping._map_attributesO  s    $;F 56L   T""&kCH,Gv%B7)L o%L  X&&))&t<CF 01L  4& ?uECS/!Lr!   )r2   r<   r   r   )rL   rM   rN   rO   rP   r   r   r>   r   rR   r   r   s   @r   r   r     s"    B H8-t r!   r   c                     \ rS rSrSrSSSSS.rSSS.rSrS	0 4S
 jr\	S 5       r
\	S 5       rS	0 4S jrS"S jrS#S jrS$S jrS$S jr S"SSSSSS.S jjr\	S 5       rS r  S%S jrS rS&S jr S$S jrS rS rS rS rS%S  jrS!rg	)'VectorPlotterih  z2Base class for objects underlying *plot functions.@index@values@columns)r7   yrX   r   r7   r   )ru   r   Nc                    0 U l         SSS.U l        U R                  X5        S H  nX2;   d  M
  [        U SU 35      " 5         M      g )NFr   rX   r   r   map_)_var_levels_var_orderedassign_variablesgetattr)r   rp   	variablesvars       r   r   VectorPlotter.__init__r  sL    
 #(e4d.
 ,CSEl+- ,r!   c                H    [        SS1[        U R                  5      -  5      $ )z.Return True at least one of x or y is defined.r7   r   )boolr   r   )r   s    r   has_xy_dataVectorPlotter.has_xy_data  s!     S#JT^^!4455r!   c                    U R                    H2  n[        U SU S3S5      =nc  M  UR                  U R                  U'   M4     U R                  $ )a  Property interface to ordered list of variables levels.

Each time it's accessed, it updates the var_levels dictionary with the
list of levels in the current semantic mappers. But it also allows the
dictionary to persist, so it can be used to set levels by a key. This is
used to track the list of col/row levels using an attached FacetGrid
object, but it's kind of messy and ideally fixed by improving the
faceting logic so it interfaces better with the modern approach to
tracking plot variables.

r6   _mapN)r   r   r2   r   )r   r   map_objs      r   
var_levelsVectorPlotter.var_levels  sP     >>C"41SE==J(/  % " r!   c           	     `   UR                  SS5      nUR                  SS5      nUc   Uc  SU l        U R                  " U40 UD6u  pVO*SU l        [        X5      nUR                  nUR
                  nXPl        X`l        U Vs0 s H  nU[        XX   US;   a  SOSS	9_M     snU l	        U $ s  snf )
z;Define plot variables, optionally using lookup from `data`.r7   Nr   r   longxyr\   r]   )boolean_type)
r`   rf   _assign_variables_wideformr   framenamesr_   r   r   rg   )	r   rp   r   r7   r   r   r   r_   vs	            r   r   VectorPlotter.assign_variables  s    MM#t$MM#t$9 &D::4M9MLE5
 !'D 1IOOEOOE 

 	 }*+t)Y  
 
s   B+c                   UR                  5        VVs/ s H  u  p4Uc  M
  UPM     nnn[        U5      (       a?  [        U5      S:  a  SOSnSU S3nUSR                  S U 5       5      -  n[	        U5      eUSL =(       d    [        U5      (       + n[        U[        5      (       a  UR                  5       n	O-[        R                  " [        R                  " U[        S	95      n	[        S
 U	 5       5      (       + n
U(       a  [        R                  " 5       n0 nX4$ U
(       a  [        R                  " U5      R                  5       nUR                   UR"                  R                   S.n0 n0 nS HG  nXR$                  ;   d  M  U R$                  U   n['        UUSS 5      X'   XR$                  U      X'   MI     [        R                  " U5      nX4$ [        U[(        5      (       a?  0 n[+        U5       H,  u  nn['        USU5      n[        R                  " U5      UU'   M.     Un[        U[,        5      (       a:  UR                  5        VVs0 s H  u  nnU[        R                  " U5      _M     nnn[        R                  " USS9nUR                  5        VVs/ s H  u  p4[/        U5      S:X  d  M  UPM     nnnUU   nSSS.nSU R0                  R                  5       ;   nU(       aq  SUS'    UR2                  R4                  nUR2                  R6                  nUR2                  R9                  S5      Ul        SnUR"                  R=                  5       US'   UR>                  " S0 UD6nU(       a%  W(       a  [        R@                  " US   WW5      US'   U R0                  R                  5        H  u  nnUU   X'   M     0 nU R0                  R                  5        H$  u  nn['        UUSS 5      n['        USS5      X'   M&     U[C        U5         nX4$ s  snnf s  snnf s  snnf ! [:         a    Sn Nf = f)a  Define plot variables given wide-form data.

Parameters
----------
data : flat vector or collection of vectors
    Data can be a vector or mapping that is coerceable to a Series
    or a sequence- or mapping-based collection of such vectors, or a
    rectangular numpy array, or a Pandas DataFrame.
kwargs : variable -> data mappings
    Behavior with keyword arguments is currently undefined.

Returns
-------
plot_data : :class:`pandas.DataFrame`
    Long-form data object mapping seaborn variables (x, y, hue, ...)
    to data vectors.
variables : dict
    Keys are defined seaborn variables; values are names inferred from
    the inputs (or None when no name can be determined).

Nru   sr#   zThe following variablez) cannot be assigned with wide-form data: z, c              3  .   #    U  H  nS U S 3v   M     g7f)`NrS   .0r   s     r   	<genexpr>;VectorPlotter._assign_variables_wideform.<locals>.<genexpr>  s     8x!q1Xxs   rY   c              3     #    U  H7  n[        U[        5      =(       a    [        U[        [        45      (       + v   M9     g 7fr   )rA   r   strbytesr  s     r   r  r    s4      
 q(#GJq3,,G(GGs   ?A)r   r   r   nameTr   r\   r   r   )var_name
value_namer   id_varsFrS   )"r   r   r*   r+   r   rA   r   r3   rC   
atleast_1dr   objectrE   	DataFramerF   r   r  indexflat_structurer   r   	enumerater	   r   wide_structurecolumns
categoriesorderedadd_categoriesAttributeError	to_seriesmeltCategoricalrB   )r   rp   rH   rI   r   assignedr  r~   emptyr3   flatr_   r   	flat_datar   r   r   	data_dictir=   val	wide_datanumeric_colsmelt_kws	use_indexorig_categoriesorig_orderedcategory_columnsobjs                                r   r   (VectorPlotter._assign_variables_wideform  s   . #),,.B.$!AA.Bx==8}q(bA*1#-VWC4998x888CS/! -CI dD!![[]F]]2::d&#ABF 

 
 

  IIz ##w 
 		$,,.I$>>#//..E
 II!---..s3D%,YQR%AIN%*+>+>s+C%DIN	 " Y/IN ##} $))	'oFAs!#vq1C &(YYs^IcN	 . ! $((<@JJLILSRYYs^+LI T5I (oo//da=3Cy3P/   ",/I %/iHH D$7$7$>$>$@@I&.#,&/&7&7&B&BO#,#4#4#<#<L(1(9(9(H(H(RI% (,$&/oo&?&?&A	(#!22I-(*y7L7F7C)E	*%
 "00668	T!*4	 9 I!00668	Tiab2!(fd!;	 9
 "$y/2I##k CH J & -',$-s/   	P!P!$P'"P-;P-8AP3 3QQc                *    [        XX#U5      nXPl        g r   )rU   _hue_map)r   rl   ro   rm   rk   mappings         r   map_hueVectorPlotter.map_hueE  s    TEDr!   c                (    [        XX#5      nX@l        g r   )r   	_size_map)r   r   ro   rm   r1  s        r   map_sizeVectorPlotter.map_sizeI  s    d57 r!   c                (    [        XX#5      nX@l        g r   )r   
_style_map)r   r   r   ro   r1  s        r   	map_styleVectorPlotter.map_styleM  s    tf<!r!   FT)reversefrom_comp_databy_facetallow_emptyr   c             #    #    Uc  / nO9[        U[        5      (       a  U/nO [        U[        5      (       a  [        U5      nU(       a7  SS1nUR	                  U[        U R                  5      [        U5      -
  -  5        U Vs/ s H  oU R                  ;   d  M  UPM     nnU(       a  U R                  n	OU R                  n	U(       a  U	R                  5       n	U R                  R                  5       n
U(       a  SS1[        U5      -   H  nU R                  U   R                  S   nU R                  U   S:X  aU  U R                  U   (       a  UR!                  X   5      X'   M]  ["        R$                  " X   R'                  5       5      X'   M  UR)                  5       R*                  nU" UR!                  X   5      5      X'   M     U(       a  U	R-                  USSSS	9n/ nU H*  nU
R/                  U5      nUR1                  Uc  / OU5        M,     [2        R4                  " U6 nU(       a  [7        [        U5      5      nU H  n[9        U5      S
:X  a  [;        [<        S5      (       a  US   OUn UR?                  U5      nURD                  (       a	  U(       d  MZ  [G        [I        UU5      5      nUUR                  5       4v   M     g0 U	R                  5       4v   gs  snf ! [@         a    U	RB                  /    n N}f = f7f)a`  Generator for getting subsets of data defined by semantic variables.

Also injects "col" and "row" into grouping semantics.

Parameters
----------
grouping_vars : string or list of strings
    Semantic variables that define the subsets of data.
reverse : bool
    If True, reverse the order of iteration.
from_comp_data : bool
    If True, use self.comp_data rather than self.plot_data
by_facet : bool
    If True, add faceting variables to the set of grouping variables.
allow_empty : bool
    If True, yield an empty dataframe when no observations exist for
    combinations of grouping variables.
dropna : bool
    If True, remove rows with missing data.

Yields
------
sub_vars : dict
    Keys are semantic names, values are the level of that semantic.
sub_data : :class:`pandas.DataFrame`
    Subset of ``plot_data`` for this combination of semantic values.

Ncolrowr7   r   r   r]   F)r   as_indexobservedru   z2.2.0)%rA   r
  r   rB   extendr   r   	comp_datar_   r   r   r   
convertersilocrg   r   convert_unitsrC   r   r   r   	transformgroupbyr`   r   r-   productreversedr*   r   rE   	get_grouprv   locr   r   r,   )r   grouping_varsr<  r=  r>  r?  r   
facet_varsr   rp   r2   axis	converterrJ  grouped_datagrouping_keysr=   	iter_keyspd_keydata_subsetsub_varss                        r   	iter_dataVectorPlotter.iter_dataQ  s    F  Ms++*OMu-- /M J  S03}3EEE
 )6O9NO>>D>>D;;=D%%'c
S%77 OOD166q9	>>$'=8((.
 (1'>'>v|'L (*wwtz/@/@/B'C ) 7 7 9 C CI#,Y-D-DV\-R#SFL 8" <<EEE ( L M$jjo$$3;RC@ % "))=9I$T)_5	  "#h!m0A"g0N0NCFTW /"."8"8"@K $$[M3 78 0 0 222' !. diik/!G Pf   /
 #'((2,K/s>   BLK#K#!GL5K(A"L(LLLLc           
     P   [        U S5      (       d  U R                  $ [        U S5      (       Gd  U R                  R                  SS9R                  SS/SSS	9nS
 GH  nX R                  ;  a  M  / nU R                  U   R                  U R                  U   SS9nU GH$  u  pVUR                  UR                  [        R                  [        R                  * /5      [        R                  5      nUR                  5       nX R                  ;   a   XfR                  U R                  U   5         n[        R                  " UR!                  U5      5      R#                  [$        5      nUR'                  5       R(                  nUR+                  [        R,                  " U" U5      UR.                  UR0                  S95        GM'     U(       a  [        R2                  " U5      n	O[        R,                  " [$        US9n	UR5                  SX)5        GM     Xl        U R6                  $ )zFDataframe with numeric x and y, after unit conversion and log scaling.ax
_comp_dataF)deepr7   r   ru   ignore)rR  errorsyxr   r  )rZ   r  r   )hasattrr_   r   dropr   rK  rG  maskisinrC   infry   r   r   rE   rh   rI  astypera   r   rJ  r   rF   r  r  concatinsertr^  )
r   rF  r   partsgroupedrS  origcomprJ  comp_cols
             r   rF  VectorPlotter.comp_data  s    tT""
 >>!t\** 5!sCjq:  nn,..-55dooc6JQV5W'.OI99TYY/@%A266JD;;=Doo-  $IIdooc.B$CD==)@)@)FGNNuUD ) 7 7 9 C CILL9T?DJJTYY!WX (/ !yy/H!yyu3?H  C2+ . (Or!   c                X   UR                  SS5      nUR                  SS5      nUb  Ub  U R                  R                  X#4   $ Ub  U R                  R                  U   $ Ub  U R                  R                  U   $ U R                  c  U R                  R                  $ U R                  $ )z>Return an Axes object based on existence of row/col variables.rB  NrA  )r`   facets	axes_dictr]  )r   rY  rB  rA  s       r   	_get_axesVectorPlotter._get_axes  s    ll5$'ll5$'?s;;((#44_;;((--_;;((--WW_;;>>!77Nr!   c                $   SSK Jn  [        X5      (       at  SU l        Xl        UR
                  R                  5       nUR                  b  UR                  U R                  S'   UR                  b  UR                  U R                  S'   OXl        SU l        U/n[        S5      R                  U R                  5      nUc  / SQnO[        U[        5      (       a  U/nU H.  nU R                  U   nX;  d  M  SU S	U S
U S3n	[        U	5      e   SSS.n
0 U l        U GH  nSSS.U   n["        R$                  " U R&                  R(                  U[*        S9n[-        U R                  SU 3S5      nUSL d  XU   :X  a   [-        US   U S35      UR.                  SS& OUSL aQ  U R1                  5        H<  u  pU R3                  U5      n[-        UU S35      UR.                  UR(                  '   M>     O[-        U R                  U S35      n[5        U5       HY  u  nnUS:X  a  US4OSU4n[-        U R                  R
                  U   U S35      nUUR.                  U R&                  U   U:H  '   M[     XR                   U'   U R&                  U   R7                  U R                   U   SS9nU H\  u  nnU R                  U   S:X  a2  U R8                  U   (       a  U R                  U   nOSn[;        UU5      nUR=                  U5        M^     GM     Uc  S=nnO Uu  nn[A        SUU45       H>  u  nnU(       d  M  U H)  n[-        USU S35      nUSL a	  U" SSS9  M!  U" SUSS9  M+     M@     U R                  R?                  SS5      S:X  a%  U H  nURB                  RE                  S5        M      gg! [         aI    U R                  R?                  S5      S:X  a  UOSnU R                  R?                  S5      S:X  a  UOSn Nf = f)a=  Associate the plotter with an Axes manager and initialize its units.

Parameters
----------
obj : :class:`matplotlib.axes.Axes` or :class:'FacetGrid`
    Structural object that we will eventually plot onto.
allowed_types : str or list of str
    If provided, raise when either the x or y variable does not have
    one of the declared seaborn types.
log_scale : bool, number, or pair of bools or numbers
    If not False, set the axes to use log scaling, with the given
    base or defaulting to 10. If a tuple, interpreted as separate
    arguments for the x and y axes.

ru   )	FacetGridNrA  rB  r   r\   r   r]   r&   z variable is z, but one of z is requiredr   r   r7   )r  r  rZ   _shareTr   rR  F_namesrc  r]   r\   set_scalelogrg  )nonpositive)baser  )#axisgridry  rA   r]  rt  axesflatten	col_namesr   	row_namesr   intersectionr   r
  rg   rz   rG  rE   rF   r_   r  r  r   rO  rZ  rv  r  rK  r   r   update_unitsr`   r,   yaxisset_inverted)r   r-  allowed_types	log_scalery  ax_listaxis_variablesr   r   r~   	facet_dim	other_varrS  share_state	axes_vars	axes_datar]  r   r$  levelidxrR  rn  	seed_dataro   scalexscaleyr~  	set_scales                                r   _attachVectorPlotter._attach  s   * 	(c%%DGKhh&&(G}}(),&}}(),&GDKeG T//?  BMs++*OM!C~~c*H,3%}XJm$o\3   n$ "  e,	!C!,S1I		(<(<3fUI!$++u~tDK
 d"ky5I&I#*71:#d|#D	a  %'040@,	!^^I69@uD\9R	ioo6 1A $DKKK=1GHE$-e$45(3u(<q!f1a&&t{{'7'7'<TlKNR	dnn[&AU&JK %5 $-OOC  nnS)11$//#2FU1SG(/$	9>>#&-7((- $ 4 $ 1)U CI&&y1 )0K "b ##FVV!* tff%56KD%u!B 'd4&,> ?I}!%V<!%eH " 7 >>c4(M9%%d+  :  V&*nn&8&8&=&JPU&*nn&8&8&=&JPUVs   !N< <APPc                   U R                   c  U R                  R                  R                   Vs/ s H  n[	        X! S35      PM     nnU Vs1 s H  oR                  5       iM     nn[        U5      S:  a  Sn[        U5      eUS   R                  5       nO'[	        U R                   U S35      R                  5       nUR                  UR                  5       R                  4$ s  snf s  snf )zDReturn a function implementing the scale transform (or its inverse).rR  ru   z=Cannot determine transform with mixed scales on faceted axes.r   )r]  rt  r  r!  r   	get_scaler*   RuntimeErrorr   rJ  inverted)r   rR  r]  	axis_listscalesr~   transform_objs          r   _get_scale_transforms#VectorPlotter._get_scale_transforms  s    77?>Bkk>N>N>S>ST>SvT]3>SIT3<=94nn&9F=6{Q V"3''%aL668M $DGGvT];IIKM&&(>(>(@(J(JJJ# U=s   C&C+c                   UR                  5       (       dJ  [        S UR                  5        5       5      nUR                  U R                  R                  SU5      US9  UR                  5       (       dK  [        S UR                  5        5       5      nUR                  U R                  R                  SU5      US9  gg)zCAdd axis labels if not present, set visibility to match ticklabels.c              3  @   #    U  H  oR                  5       v   M     g 7fr   get_visibler  ts     r   r  1VectorPlotter._add_axis_labels.<locals>.<genexpr>       J5IMMOO5I   r7   )visiblec              3  @   #    U  H  oR                  5       v   M     g 7fr   r  r  s     r   r  r    r  r  r   N)	
get_xlabelr   get_xticklabels
set_xlabelr   r`   
get_ylabelget_yticklabels
set_ylabel)r   r]  	default_x	default_y	x_visible	y_visibles         r   _add_axis_labelsVectorPlotter._add_axis_labels  s     }}JR5G5G5IJJIMM$..,,S)<iMP}}JR5G5G5IJJIMM$..,,S)<iMP r!   c                |  ^ ^^ T R                   n[        U[        5      (       a  US;  a  Sn[        U5      eUSL a  Sn/ m0 mUc  0 OUR	                  5       nUc  0 OUR	                  5       nU 4S jS 5        Vs1 s H
  nUc  M  UiM     n	n[        U	5      S:w  a  S	OU	R                  5       n[        S
SSSS	S	S9n
UU4S jnUc  SSS/SS.nUR                  5        H(  u  pT R                  XXhXUR                  U5      5        M*     0 n/ nUR                  SS
5      c  UR                  S5        T GHc  nUu  nnTU   n0 n/ T R                  QUQUR                  5        VVs/ s H  nU  H  nUPM     M     snnQnU H  nUU;   d  M  UU   UU'   M     U" SSU0SS0UEUED6n[        [        S5      (       a  [        U[        R                  R                   5      (       a  UR#                  U5        O[        U[        R$                  R&                  5      (       a  UR)                  U5        OL[        U[        R*                  R,                  5      (       a  UR/                  U5        OUR1                  U5        UUU'   UR3                  U5        GMf     UT l        UT l        UT l        gs  snf s  snnf )z>Add labeled artists to represent the different plot semantics.)autobrieffullz7`legend` must be 'auto', 'brief', 'full', or a boolean.Tr  Nc              3  \   >#    U  H!  nTR                   R                  US 5      v   M#     g 7fr   )r   r`   )r  r   r   s     r   r  0VectorPlotter.add_legend_data.<locals>.<genexpr>  s'     K2JQT^^4((2Js   ),r   ru   r#   Fwr   )r  colorr  	linewidthr   r   c                   > X4nUT;   a  TU   R                   " S0 UD6  g TR                  U5        [        S0 UD6TU'   g )NrS   )updater   r   )r  val_namekwsr=   keys
legend_kwss       r   r  -VectorPlotter.add_legend_data.<locals>.update  sC    $Cj 3&&--C "&++
3r!   r  r  r  labelz.2z3.5.0rS   )legendrA   r
  r   r   r*   popr   r   _update_legend_datar`   _legend_attributesr3   r   r   linesLine2Dadd_linepatchesPatch	add_patchcollections
Collectionadd_collection
add_artistr   legend_titlelegend_datalegend_order)r   r]  func
common_kwsattrssemantic_kws	verbosityr~   titletitles	title_kwsr  r   r   r  r  r=   r6   r  r  	level_kws	var_attrsr   	use_attrsartistr  r  s   `                        @@r   add_legend_dataVectorPlotter.add_legend_data  s    KK	i%%);T*TKCS/!$I
%-R:??3D
)1r|7H7H7J L2JK
K  K 	 

 &kQ&FJJLQr"
		. =#k3-?$OE++-JC$$YyAQAQRUAV (
  >>'5)1NN7#CHAuS/CI(( )5(;(;(=T(=9)$$)$(=TI
 "3;&)$iIdO " TT'4)S:)S)STF g..fcii&6&677KK'(9(9::LL((B(BCC%%f-f%%K$1 4 "&({
R Us   ;J3J3'J8
c           
        Sn[        U SU S3S5      n	U	c  gU	R                  S:H  =(       a0    US:H  =(       d$    US:H  =(       a    [        U	R                  5      U:  n
U
(       a  [	        U	R
                  [        R                  R                  5      (       a  [        R                  R                  US9nO[        R                  R                  US	9n[        U	R                  5      [        U	R                  5      4n[        XU R                  U   R!                  5       R"                  5      u  pOU	R                  c  / =pOU	R                  =pU(       dC  U R$                  R'                  US5      b&  U" U R$                  U   S
4U R$                  U   40 UD6  Uc  0 OUn[)        X5       H  u  nnUc  M  U	" U5      n[	        U[*        5      (       a  U Vs0 s H  nUU_M     nnOUb  UU0nUR-                  UR/                  5        VVs0 s H  u  nnUU;   d  M  UUU   _M     snn5        U" U R$                  U   U40 UD6  M     gs  snf s  snnf )z1Generate legend tick values and formatted labels.r'   r6   r   Nr\   r  r  )numticks)nbinsr  )r   r   r*   r2   rA   rm   r   r   LogNormticker
LogLocatorMaxNLocatorr   r   r   r_   infer_objectsrZ   r   r`   r,   rB   r  r   )r   r  r   r  r  r  
attr_namesother_propsbrief_ticksmapperr  locatorlimitsr2   formatted_levelsr  formatted_levelr   r  rI   r   s                        r   r  !VectorPlotter._update_legend_data  s$    3%t}d3>9, 
  JV#HFMM(:[(H 	 &++szz'9'9::**///E**00{0C'V]]);;F'@!4!B!B!D!J!J($F$ ]]"(**F%(.5F++C6BDNN3'14>>#3FT)T'/b[&)&&C"E? e}j$//3=>:4D$J:D>D+&-D[5F5F5HW5HTQEUVJ[Q%[5HWXt~~c*ODtD 'D ? Xs   II
Ic                    [         er   NotImplementedErrorr   rR  rG   rH   s       r   scale_nativeVectorPlotter.scale_native:  s
     "!r!   c                    [         er   r  r   s       r   scale_numericVectorPlotter.scale_numeric@  
    
 "!r!   c                    [         er   r  r   s       r   scale_datetimeVectorPlotter.scale_datetimeG  r  r!   c                   [        SSS/U5        XR                  ;  a-  SU R                  U'   SU R                  U'   SU R                  U'   U R                  U   S:X  a  U R                  R	                  USS	9U l        U R                  U   R                  5       nUSL=(       d    UR                  R                  S
:H  U R                  U'   [        R                  " [        XB5      US9nUb#  UR                  U5      nUR                  U5      nO*UR                  [        5      nUR                  [        5      nX R                  U'   SU R                  U'   X@R                  U'   U $ )a2  
Enforce categorical (fixed-scale) rules for the data on given axis.

Parameters
----------
axis : "x" or "y"
    Axis of the plot to operate on.
order : list
    Order that unique values should appear in.
formatter : callable
    Function mapping values to a string representation.

Returns
-------
self

rR  r7   r   Nr]   r#   r\   	mergesort)kindcategoryrd  )r   r   rg   r_   sort_valuesr   rZ   r  r   rE   Indexr   maprj  r
  r   )r   rR  ro   	formattercat_datas        r   scale_categoricalVectorPlotter.scale_categoricalN  sD   T 	c
D1 ~~%#'DNN4 #0DNN4 #%DNN4  >>$9,!^^77;7ODN >>$'..0 #(t"3"Xx~~7J7Jj7X$*8;$G  ||I.HIIi(Es+HLL%E !&  -t  (tr!   )r^  r0  r5  r9  r   r   r]  rG  rt  rf   r  r  r  r_   rg   r   r   r   r   )NN)r#   r#   )rL   rM   rN   rO   rP   r  r  r   r   propertyr   r   r   r   r2  r6  r:  rZ  rF  rv  r  r  r  r  r  r  r  r  r  rR   rS   r!   r   r   r   h  s    < Ij:N $)4N B ." 6 6    " %)B :L$\ !"
 !u"e5u"n * *X$ 	G,VK,Q CGP)d/El"""[r!   r   c                  6   ^  \ rS rSrSrSrU 4S jrS rSrU =r	$ )VariableTypei  z
Prevent comparisons elsewhere in the library from using the wrong name.

Errors are simple assertions because users should not be able to trigger
them. If that changes, they should be more verbose.

rz  c                P   > XR                   ;   d   U5       e[        TU ]	  U5        g r   )allowedr^   r   )r   rp   rr   s     r   r   VariableType.__init__  s%    ||#)T)#r!   c                L    XR                   ;   d   U5       eU R                  U:H  $ r   )r  rp   )r   others     r   __eq__VariableType.__eq__  s&    $+e+$yyE!!r!   rS   )
rL   rM   rN   rO   rP   r  r   r  rR   r   r   s   @r   r  r    s     3G" "r!   r  c                   [         R                  " U 5      n [        U R                  [         R                  5      (       a  [        S5      $ [         R                  " U 5      R                  5       (       a  [        S5      $ U R                  5       n [        R                  " 5          [        R                  " S[        [        4S9   [        R                  " U SS/5      R                  5       (       a  [        U5      sSSS5        $  SSS5        [         R"                  R$                  R'                  U 5      (       a  [        S5      $ [         R"                  R$                  R)                  U 5      (       a  [        S5      $ S	 nU" U 5      (       a  [        S5      $ S
 nU" U 5      (       a  [        S5      $ [        S5      $ ! [          a     Nf = f! , (       d  f       N= f)a  
Determine whether a vector contains numeric, categorical, or datetime data.

This function differs from the pandas typing API in two ways:

- Python sequences or object-typed PyData objects are considered numeric if
  all of their entries are numeric.
- String or mixed-type data are considered categorical even if not
  explicitly represented as a :class:`pandas.api.types.CategoricalDtype`.

Parameters
----------
vector : :func:`pandas.Series`, :func:`numpy.ndarray`, or Python sequence
    Input data to test.
boolean_type : 'numeric' or 'categorical'
    Type to use for vectors containing only 0s and 1s (and NAs).

Returns
-------
var_type : 'numeric', 'categorical', or 'datetime'
    Name identifying the type of data in the vector.
r]   r\   r`  )actionr  r   ru   Nr   c                D    U  H  n[        U[        5      (       a  M    g   gNFT)rA   r
   r7   x_is     r   all_numeric"variable_type.<locals>.all_numeric  s!    Cc6**  r!   c                d    U  H*  n[        U[        [        R                  45      (       a  M*    g   gr"  )rA   r   rC   
datetime64r#  s     r   all_datetime#variable_type.<locals>.all_datetime  s*    CcHbmm#<==  r!   )rE   rF   rA   rZ   CategoricalDtyper  rc   rd   r   r/   catch_warningssimplefilterFutureWarningDeprecationWarningrC   rh  rz   apitypesis_numeric_dtypeis_datetime64_dtype)vectorr   r%  r)  s       r   r   r     s|   . YYvF &,, 3 344M** 
wwvI&& ]]_F 
	 	 	"}6H&I	
	wwv1v&**,,#L1 
#	"
 - 
# 
vv||$$V,,I&&	vv||''//J'' 6I&& FJ'' &&M  	 	 
#	"s0   $ G6GG
GGGG
Gc                   U c  SO
[        U 5      nUc  SO
[        U5      nSnSnU cn  [        U5      R                  S5      (       a&  [        R                  " UR                  SS5      5        U(       a!  US:w  a  [        UR                  SS5      5      eg	Ucn  [        U5      R                  S
5      (       a&  [        R                  " UR                  SS	5      5        U(       a!  US:w  a  [        UR                  SS	5      5      eg[        U5      R                  S
5      (       d  US	:X  a)  U(       a!  US:w  a  [        UR                  SS5      5      eg	[        U5      R                  S5      (       d  US:X  a)  U(       a!  US:w  a  [        UR                  SS	5      5      egUb  S[        U5       S3n[        U5      eUS:w  a  US:X  a  gUS:w  a  US:X  a  g	US:X  a  US:w  a  gU(       a  SXE4;  a  Sn[        U5      eg	)a  Determine how the plot should be oriented based on the data.

For historical reasons, the convention is to call a plot "horizontally"
or "vertically" oriented based on the axis representing its dependent
variable. Practically, this is used when determining the axis for
numerical aggregation.

Parameters
----------
x, y : Vector data or None
    Positional data vectors for the plot.
orient : string or None
    Specified orientation. If not None, can be "x" or "y", or otherwise
    must start with "v" or "h".
require_numeric : bool
    If set, raise when the implied dependent variable is not numeric.

Returns
-------
orient : "x" or "y"

Raises
------
ValueError: When `orient` is an unknown string.
TypeError: When dependent variable is not numeric, with `require_numeric`

Nz.{} orientation requires numeric `{}` variable.z0{} orientation ignored with only `{}` specified.h
Horizontalr   r\   Verticalr7   r   z5`orient` must start with 'v' or 'h' or be None, but `z` was passed.r]   z7Neither the `x` nor `y` variable appears to be numeric.)	r   r
  
startswithr/   r0   r   rz   reprr   )	r7   r   orientrequire_numericx_typey_typenonnumeric_dv_errorsingle_var_warningr~   s	            r   infer_orientrA    s   : YTM!$4FYTM!$4FJKyv;!!#&&MM,33L#FGv2/66z3GHH	
v;!!#&&MM,33JDEv2/66|SIJJ	V			$	$#v2/66z3GHH	V			$	$#v2/66|SIJJ		L>0 	 o	=	 V}%<	9	9!4	9	9!4	Yv.>>Gn r!   c                  ^ / SQnSn[        U5      U :  a  [        R                  " SS/U5      n[        R                  " SS/U5      n[        R                  " [	        [        U5      SS SSS2   [        U5      SS 5      6 nU HE  n[        U5      m[        [        R                  " U4S jU 5       6 5      nUR                  U5        MG     US-  n[        U5      U :  a  M  USU  $ )	a  Build an arbitrarily long list of unique dash styles for lines.

Parameters
----------
n : int
    Number of unique dash specs to generate.

Returns
-------
dashes : list of strings or tuples
    Valid arguments for the ``dashes`` parameter on
    :class:`matplotlib.lines.Line2D`. The first spec is a solid
    line (``""``), the remainder are sequences of long and short
    dashes.

)r#   )r[         ?)ru   ru   )         ?rC  rE  )   ru   ru   ru   rD  rE  r[   ru   r   Nc              3  *   >#    U  H  oT4v   M
     g 7fr   rS   )r  seggaps     r   r   unique_dashes.<locals>.<genexpr>  s     *J#:s   )	r*   r-   combinations_with_replacementchainr,   rB   r   r   r   )	nr   pabsegment_listsegmentsspecrI  s	           @r   r   r   o  s    $F 	
A
f+/ 33QIqA33QFA> !GAbM$B$GAbM)
  %Hh-C*J*JKLDMM$ %
 	
Q% f+/( "1:r!   c                    / SQnSn[        U5      U :  aH  SUS-   -  S-  nUR                  US-   SU4US-   SU4USS4USS4/5        US-  n[        U5      U :  a  MH  USU  $ )a/  Build an arbitrarily long list of unique marker styles for points.

Parameters
----------
n : int
    Number of unique marker specs to generate.

Returns
-------
markers : list of string or tuples
    Values for defining :class:`matplotlib.markers.MarkerStyle` objects.
    All markers will be filled.

)	oX)r[   r   -   P)r[   r   r   )r[   ru   r   ^)r[   ru   rW  r   rF  ih  ru   r   r   N)r*   rE  )rM  r   r  rO  s       r   r   r     s     
G 	
A
g,
1q5MAUAqMUAqM1I1I	
 	 	
Q g,
 2A;r!   c                z   UcO  [        U S5      (       a  U R                  nO U R                  R                  n[        [
        R                  U5      n[        U5      $ ! [        [        4 aL    [
        R                  " U 5      R                  5       n[        U 5      S:X  a  [        R                  " U5      n Nf = f)a  Return a list of unique data values.

Determine an ordered list of levels in ``values``.

Parameters
----------
vector : list, array, Categorical, or Series
    Vector of "categorical" values
order : list-like, optional
    Desired order of category levels to override the order determined
    from the ``values`` object.

Returns
-------
order : list
    Ordered list of category levels not including null values.

r  r\   )re  r  catrz   r  rE   rF   r   r   rC   r   filternotnullrB   )r4  ro   s     r   r   r     s    & }6<((%%E+

-- rzz5); ~. +		&)002 (I5GGENE+s   A AB:9B:)r\   )NNNTr   )+
__future__r   r/   r-   r   r  r   collections.abcr   r   r	   numbersr
   r   numpyrC   pandasrE   
matplotlibr   seaborn._core.datar   seaborn.palettesr   r   seaborn.utilsr   r   r   r   r   r   r   rU   r   r   r   r  r   rA  r   r   r   rS   r!   r   <module>rg     s    "    " 7 7      ' 8= 8=vO0 O0dZ6/ Z6z[? [BA AH": "(Y'xPf0f+\!r!   