
    *gUG                        d dl mZ d dlmZmZmZ d dlZd dlmZ d dl	Z
d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlZd dlmc mZ d dlmZ d dlm Z m!Z! d dl"m#Z# d dl$m%Z% d dl&m'Z'm(Z(m)Z) erd dl*m+Z+ d dl,m-Z- d dl.m/Z/ d dl0m1Z1 d dl2m3Z3 ddZ4 G d de       Z5ddZ6	 	 	 	 	 	 	 	 d	 	 	 	 	 d dZ7	 	 	 	 	 	 	 	 	 d!	 	 	 	 	 	 	 d"dZ8	 	 	 	 	 	 	 	 	 d!	 	 	 	 	 	 	 d"dZ9	 	 	 	 	 	 	 	 	 	 d#	 	 	 	 	 	 	 	 	 	 	 	 	 d$dZ:y)%    )annotations)TYPE_CHECKINGLiteral
NamedTupleN)setp)lib)cache_readonly)find_stack_level)is_dict_like)	ABCSeries)remove_na_arraylike)pprint_thing)LinePlotMPLPlot)create_iter_data_given_by)get_standard_colors)create_subplotsflatten_axesmaybe_adjust_figure)
Collection)Axes)Figure)Line2D)MatplotlibColorc                ,   |r| j                         n| j                         }t        |      t        |      k7  r2t        t        |      t        |            \  }}|dk(  sJ |       ||z  }|r | j                  |fi | y | j
                  |fi | y)zSet the tick labels of a given axis.

    Due to https://github.com/matplotlib/matplotlib/pull/17266, we need to handle the
    case of repeated ticks (due to `FixedLocator`) and thus we duplicate the number of
    labels.
    r   N)
get_xticks
get_ytickslendivmodset_xticklabelsset_yticklabels)axlabelsis_verticalkwargsticksi	remainders          m/var/www/html/articles-backend/trend/venv/lib/python3.12/site-packages/pandas/plotting/_matplotlib/boxplot.py_set_ticklabelsr*   /   s      +BMMOE
5zS[ c%j#f+69A~(y(~!6,V,6,V,    c                      e Zd Zedd       ZdZdZ G d de      ZdddZ	e
	 d	 	 	 	 	 dd       Zd Zed	        Zed
        Zed        Zed        Zed        Z	 	 d	 	 	 ddZddZddZddZddZedd       Ze fd       Z xZS ) BoxPlotc                     y)Nbox selfs    r)   _kindzBoxPlot._kindB   s    r+   
horizontal)Naxesdictbothc                  "    e Zd ZU ded<   ded<   y)
BoxPlot.BPr   r"   zdict[str, list[Line2D]]linesN)__name__
__module____qualname____annotations__r0   r+   r)   BPr9   J   s    &&r+   r?   c                    || j                   vrt        d      || _        t        j                  | |fi | | j
                  r| j                  dk(  rd| _        y d| _        y y )Nz2return_type must be {None, 'axes', 'dict', 'both'}verticalF)	_valid_return_types
ValueErrorreturn_typer   __init__subplotsorientationsharexsharey)r2   datarD   r%   s       r)   rE   zBoxPlot.__init__O   sc    d666QRR&t.v.== :-## r+   c                t   |j                   dk(  r[|D cg c]  }t        |       }}|D cg c]7  }|j                  dkD  r|n#t        j                  t        j
                  g      9 }}nt        |      } |j                  |fi |}|dk(  r||fS |dk(  r| j                  ||      |fS ||fS c c}w c c}w )N   r   r6   r7   r"   r:   )ndimr   sizenparraynanboxplotr?   )	clsr"   y
column_numrD   kwdsvysbps	            r)   _plotzBoxPlot._plot`   s    
 66Q;234Q%a(4B4 DFFaqvvz!rxx'99FBF$Q'BRZZ#d#& r6MF"66Rr6*B..r6M 5 Gs
   B0<B5c                    |t         j                  u ry |t        j                  dt	                      t        |t              r g d}|D ]  }||vst        d| d|        |S )NzC'color' and 'colormap' cannot be used simultaneously. Using 'color')
stacklevelboxeswhiskersmedianscaps!color dict contains invalid key ''. The key must be either )r   
no_defaultwarningswarnr
   
isinstancer6   rC   )r2   colorcolormap
valid_keyskeys        r)   _validate_color_argszBoxPlot._validate_color_argsv   s    CNN"MM0+- eT"AJ j($;C5 A22<?  r+   c                2    t        d| j                  d       S )N   )
num_colorsrj   ri   )r   rj   r1   s    r)   _color_attrszBoxPlot._color_attrs   s     #a$--tTTr+   c                     | j                   d   S Nr   rq   r1   s    r)   _boxes_czBoxPlot._boxes_c         ##r+   c                     | j                   d   S rs   rt   r1   s    r)   _whiskers_czBoxPlot._whiskers_c   rv   r+   c                     | j                   d   S )NrL   rt   r1   s    r)   
_medians_czBoxPlot._medians_c   rv   r+   c                     | j                   d   S rs   rt   r1   s    r)   _caps_czBoxPlot._caps_c   rv   r+   c                     y Nr0   )r2   rp   
color_kwdss      r)   _get_colorszBoxPlot._get_colors   s     	r+   c                v   t        | j                  t              r| j                  j                  d| j                        }| j                  j                  d| j
                        }| j                  j                  d| j                        }| j                  j                  d| j                        }nh| j                  xs | j                  }| j                  xs | j
                  }| j                  xs | j                  }| j                  xs | j                  }||||f}t        |fd|i| j                   y )Nr_   r`   ra   rb   	color_tup)
rh   ri   r6   getru   rx   rz   r|   maybe_color_bprW   )r2   rZ   r_   r`   ra   rb   r   s          r)   r   zBoxPlot.maybe_color_bp   s    djj$'JJNN7DMM:Ezz~~j$2B2BCHjjnnY@G::>>&$,,7D JJ/$--Ezz5T%5%5Hjj3DOOG::-DHgt4	r<Y<$))<r+   c                L   | j                   rt        j                  t              | _        | j
                   t        | j                  | j                        n| j                  }t        | j                  |            D ]  \  }\  }}| j                  |      }| j                  j                         }| j
                  b|j                  }|j                  t!        |             | j                  j"                  j$                  }|d   D 	cg c]  }	t!        |	       }
}	nt!        |      g}
 | j&                  ||f|| j(                  d|\  }}| j+                  |       || j                  |<   t-        ||
| j.                  dk(          y | j                  j0                  j                  }| j                  d      }| j                  j                         } | j&                  ||fd| j(                  d|\  }}| j+                  |       || _        | j                  j"                  D cg c]  }t!        |       }}| j2                  s*t5        t7        |            D cg c]  }t!        |       }}t-        ||| j.                  dk(         y c c}	w c c}w c c}w )Ndtype)rJ   r   )rV   rD   rA   )r"   r#   r$   )rF   pdSeriesobject_return_objbyr   rJ   r3   	enumerate
_iter_data_get_axrW   copyT	set_titler   columnslevelsr[   rD   r   r*   rG   values	use_indexranger   )r2   figrJ   r'   labelrU   r"   rW   r   col
ticklabelsretrZ   leftr#   rl   s                   r)   
_make_plotzBoxPlot._make_plot   sM   ==!yyv6D
 77& *$))TZZ@YY  "+4???+E!F :E1\\!_yy~~' 77&ALLe!45
 "YY..55F?Eay!I,s"3!IJ!I".u"5!6J$$**&'T5E5EIMR ##B'*-  '*$:J:Jj:X/6 		  ""AaB99>>#D djjA"#1A1AEIGC #"D59YY5F5FGTl4(GFG>>7<S[7IJ,s+JJf$2B2Bj2P5 "J. HJs   J1J'J!c                     y r~   r0   r1   s    r)   _make_legendzBoxPlot._make_legend   s    r+   c                    | j                   r$|j                  t        | j                                | j                  r%|j	                  t        | j                               y y r~   )xlabel
set_xlabelr   ylabel
set_ylabel)r2   r"   rJ   s      r)   _post_plot_logiczBoxPlot._post_plot_logic   s?    ;;MM,t{{34;;MM,t{{34 r+   c                >    | j                   j                  dd      ryy)NvertTrA   r4   )rW   r   r1   s    r)   rG   zBoxPlot.orientation  s    99==&r+   c                H    | j                   
t        |   S | j                  S r~   )rD   superresultr   )r2   	__class__s    r)   r   zBoxPlot.result	  s%    #7>!###r+   )returnzLiteral['box'])r5   )rD   strr   None)Nr5   )r"   r   rU   z
np.ndarrayrD   r   )Nri   )r   zQdict[str, MatplotlibColor] | MatplotlibColor | Collection[MatplotlibColor] | Noner   r   r   r   )r   r   r   r   )r"   r   r   r   )r   z!Literal['horizontal', 'vertical'])r;   r<   r=   propertyr3   _layout_typerB   r   r?   rE   classmethodr[   rm   r	   rq   ru   rx   rz   r|   r   r   r   r   r   rG   r   __classcell__)r   s   @r)   r-   r-   A   s-      L8'Z '
$" JP$DG ** U U $ $ $ $ $ $ $ $
   
="8t5     $ $r+   r-   c                .   |j                  d      st        | d   |d   d       |j                  d      st        | d   |d   d       |j                  d      st        | d	   |d
   d       |j                  d      st        | d   |d   d       y y )Nboxpropsr_   r      )ri   alphawhiskerpropsr`   medianpropsra   rL   cappropsrb   ro   )r   r   )rZ   r   rW   s      r)   r   r     s     88JR[	!A688N#R
^9Q<q988M"R	])A,a888JRZy|15  r+   c
                P   |j                  |d      }|Bt        |t        t        f      s|g}|j	                         j
                  j                  |      }t        |      }t        ||
j                  dd      |
j                  dd      |||      \  }}t        |      }|
j                  dd       |
j                  dd       }}|
j                  d	d      r|xs |}n|xs |}g }t        |      D ][  \  }}||   }||   }t        | \  }} | |||f||d
|
}|j                  |       |j                  |       |j!                  |       ] t#        j$                  ||d      }|	|}t        |      dk(  r|d   n|}|j'                  d|        t)        |ddddd       |S )NF)observedrH   TrI   )naxesrH   rI   figsizer"   layoutr   r   r   )r   r   )indexr   r   r   zBoxplot grouped by 333333??皙?皙?bottomtopr   rightwspace)groupbyrh   listtuple_get_numeric_datar   
differencer   r   popr   r   r   zipr   appendgridr   r   suptitler   )plotfrJ   r   r   numeric_onlyr   r   r"   r   rD   r%   groupedr   r   r5   _axesr   r   	ax_valuesr'   r   gp_colkeysr   re_plotfr   bylines                              r)   _grouped_plot_by_columnr     s    ll2l.G"tUm,B((*22==bALEzz(D)zz(D)IC E ZZ$/Hd1KFFzz&$22IG$ 31XF|fvrR&R6R
S"
 YYye<F "glRUFLL&vh/0Dc3sSMr+   c
                  	
 dd l m} 	t        j                  vrt	        d      t        | t              r| j                  d      } d}
fd}d	fd} |       |d }nt        |t        t        f      r|}n|g}|t        || f||||||	d
}|S 	d	|t	        d      |2|d	|ini }|j                  |      5  |j                         }d d d        | j                         } t        | j                        }|dk(  rt	        d
      || j                  }n| |   }  ||| j                   j"                  |fi 
}|j%                  |       |S # 1 sw Y   xY w)Nr   z,return_type must be {'axes', 'dict', 'both'}xc                    t        d      } t        j                  | g d      } t        j                  | d      } j	                  dd       }|rut        |      rYg d}t        t        |t        d                  }|j                         D ]"  \  }}||v r	|| ||   <   t        d| d	|        | S | j                  |       | S )
Nro   )rp   )r   r   rL   kri   r^      rc   rd   )r   rP   taker   r   r   r6   r   r   itemsrC   fill)r   colorsrk   key_to_indexrl   valuerW   s         r)   r   zboxplot.<locals>._get_colorsr  s     %2+63''4(F# F
#C
E!H$=>"(,,. JCj(49|C01(?u E66@\C 	  F#r+   c                V   |j                  dd       |j                  dd       }}|r|j                  t        |             |r|j                  t        |             | D cg c]  }t        |       } }|D cg c]&  }t	        j
                  t        |      t              ( }} |j                  |fi |}
|j                  d
       t        || |j                  dd             t        |fd		i| d
k(  r|S dk(  rt        j                  ||      S |S c c}w c c}w )Nr   r   r   r7   )axis	labelsizer   T)r"   r#   r$   rotationr   r6   rM   )r   r   r   r   rP   asarrayr   r   rS   tick_paramsr*   r   r   r-   r?   )r   r   r"   rW   r   r   r   rX   rZ   r   fontsizerD   rots            r)   
plot_groupzboxplot.<locals>.plot_group  s   (D1488Hd3KMM,v./MM,v./)-.AQ..LRSq"**036BSSRZZ'$'NN(N; 	$DHHVT,BS	
 	r4V4t4 & IF"::2:..I% /Ss   "D!:+D&)r   r   r   r   r"   r   rD   r5   z7The 'layout' keyword is not supported when 'by' is Nonezfigure.figsizez;boxplot method requires numerical columns, nothing to plot.)r"   r   )matplotlib.pyplotpyplotr-   rB   rC   rh   r   to_framer   r   r   
rc_contextgcar   r   r   r   r   r   )rJ   columnr   r"   r   r   r   r   r   rD   rW   pltr   r   r   r   rcr   r   s       ``   ``       @r)   rS   rS   [  s    $ '555GHH$	"}}S!: 8 ]F~	FT5M	*(	~ )
 #
 
H M/  KVWW:070C"G,B# WWY%%'DLL!A:M  ?llG=DGT[[]]B?$?
M! s   EE$c
                ^    dd l m} t        | f|||||||||	d	|
}|j                          |S )Nr   )	r   r   r"   r   r   r   r   r   rD   )r   r   rS   draw_if_interactive)r2   r   r   r"   r   r   r   r   r   rD   rW   r   s               r)   boxplot_framer     sQ     $	

 
B Ir+   c                   |du rt        |       }t        |d||	|
||      \  }}t        |      }t        j                  t
              }t        | |      D ]I  \  \  }}} |j                  d|||||d|}|j                  t        |             ||j                  |<   K t        |ddddd	
       |S t        |  \  }}| j                  dk(  rt        j                  ||d      }n+t        |      dkD  r|d   j                  |dd        }n|d   }|Kt        j                   |      }t        j"                  j%                  ||g      }t'        |j(                        } |j                  d|||||||d|}|S )NTF)r   squeezer"   rH   rI   r   r   r   )r"   r   r   r   r   r   r   r   r   r   r   r   )r   r   )r   r   r   r   r"   r   r   r0   )r   r   r   r   r   r   r   rS   r   r   locr   r   concatjoincomconvert_to_list_like
MultiIndexfrom_productr   r   )r   rF   r   r   r   r   r"   r   r   rH   rI   rW   r   r   r5   r   rl   groupdr   framesdf	multi_keys                          r)   boxplot_frame_groupbyr    s    4G#
	T D!iif% #GT 2 	LS%" fxStOSA LLc*+CGGCL	 	C#CsSVW8 J5 G}f<<1615B[1_qs,BB --f5F22D&>BI)**+Fbjj 	
	
 	
 Jr+   )r"   r   r#   z	list[str]r$   boolr   r   r   )NNTFNNNN)r   r  r   r  r   tuple[float, float] | None)	NNNNr   TNNN)r   
int | Noner   intr   r  r   r  )
TNNr   TNNNFT)rF   r  r   r  r   r  r   r  r   r  rH   r  rI   r  );
__future__r   typingr   r   r   rf   matplotlib.artistr   numpyrP   pandas._libsr   pandas.util._decoratorsr	   pandas.util._exceptionsr
   pandas.core.dtypes.commonr   pandas.core.dtypes.genericr   pandas.core.dtypes.missingr   pandasr   pandas.core.commoncorecommonr  pandas.io.formats.printingr    pandas.plotting._matplotlib.corer   r   #pandas.plotting._matplotlib.groupbyr   !pandas.plotting._matplotlib.styler   !pandas.plotting._matplotlib.toolsr   r   r   collections.abcr   matplotlib.axesr   matplotlib.figurer   matplotlib.linesr   pandas._typingr   r*   r-   r   r   rS   r   r  r0   r+   r)   <module>r)     s   " 
  "   2 4 2 0 :      3 J A  *$('.-$M$h M$`
6  *.:
 : : (:~ *.
  
  (H *.
  
  (D *.?? 	?
 
? ? (? ? ?r+   