
    A>iD                    @   S r SSKJr  SSKJr  SSKrSSKJr  SSK	r
SSK	Jr  SSKJr  \(       a  SSKJr  SSKJr  SS	 jrSS
 jrS rS S jrS S!S jjrS rS"S jrS rS#S jrS$S jrS"S jrS%S jrS&S jr SS jr S'S jr!S(S jr"S r#S r$S)S jr%S*S jr&S r'S r(g)+zF
Module consolidating common testing functions for checking plotting.
    )annotations)TYPE_CHECKINGN)is_list_like)Series)SequenceAxesc                   U(       a  Uc  [        S5      e[        U 5      n U  HZ  nU(       a=  UR                  5       c   e[        UR                  5       R	                  5       U5        MG  UR                  5       c  MZ   e   g)a  
Check each axes has expected legend labels

Parameters
----------
axes : matplotlib Axes object, or its list-like
labels : list-like
    expected legend labels
visible : bool
    expected legend visibility. labels are checked only when visible is
    True
Nz-labels must be specified when visible is True)
ValueError_flatten_visible
get_legend_check_text_labels	get_texts)axeslabelsvisibleaxs       [/var/www/html/land-tabula/venv/lib/python3.13/site-packages/pandas/tests/plotting/common.py_check_legend_labelsr      sk     FNHIID!D==?...r}}88:FC==?***     c                    U(       a  Uc  [        S5      eU(       a9  U R                  5       u  p4U Vs/ s H  oUR                  5       PM     nnXa:X  d   egU R                  5       b   egs  snf )z
Check ax has expected legend markers

Parameters
----------
ax : matplotlib Axes object
expected_markers : list-like
    expected legend markers
visible : bool
    expected legend visibility. labels are checked only when visible is
    True
Nz.Markers must be specified when visible is True)r   get_legend_handles_labels
get_markerr   )r   expected_markersr   handles_handlemarkerss          r   _check_legend_markerr   /   sj     $,IJJ113
5<=W6$$&W=***}}&&& >s   A*c                
   U R                  5       nUR                  5       n[        U5      [        U5      :X  d   e[        X#SS9 H;  u  pEUR                  5       nUR                  5       n[        R
                  " Xg5        M=     g)zt
Check each axes has identical lines

Parameters
----------
xp : matplotlib Axes object
rs : matplotlib Axes object
TstrictN)	get_lineslenzip
get_xydatatmassert_almost_equal)xprsxp_linesrs_linesxplrslxpdatarsdatas           r   _check_datar1   F   si     ||~H||~Hx=CM)))48!!
v. 9r   c                    SSK Jn  [        X5      (       d  [        U 5      (       d  U /n U  H  nUR	                  5       U:X  a  M   e   g)z
Check each artist is visible or not

Parameters
----------
collections : matplotlib Artist or its list-like
    target Artist or its list or collection
visible : bool
    expected visibility
r   )
CollectionN)matplotlib.collectionsr3   
isinstancer   get_visible)collectionsr   r3   patchs       r   _check_visibler9   Y   sD     2k..|K7P7P"m  "g--- r   c                v    [        U 5      n U  H(  nUR                   H  nUR                  U:X  a  M   e   M*     g)z
Check for each artist whether it is filled or not

Parameters
----------
axes : matplotlib Axes object, or its list-like
filled : bool
    expected filling
N)r   patchesfill)r   filledr   r8   s       r   _check_patches_all_filledr>   m   s8     D!DZZE::'''   r   c                    U R                  5       n[        [        X!5      5      nU R                   Vs/ s H  oCU   PM	     sn$ s  snf N)uniquedictr%   values)seriescolorsrA   mappedvs        r   _get_colors_mappedrH   ~   s<    ]]_F #f%&F%}}-}!1I}---s   Ac                x   SSK Jn  SSKJnJnJn  SSKJn  UR                  n	Ub  Ub  [        X15      nUS[        U 5       n[        U 5      [        U5      :X  d   e[        XSS9 H  u  p[        X5      (       a"  U
R                  5       nU	R                  U5      nO?[        XU45      (       a  [        U
R!                  5       S   5      nOU
R!                  5       nU	R                  U5      nX:X  a  M   e   Ub  Ub  [        X25      nUS[        U 5       n[        U 5      [        U5      :X  d   e[        XSS9 H{  u  p[        X5      (       a  U
R#                  5       S   nOU
R#                  5       n[        U[$        R&                  5      (       a  [        U5      nU	R                  U5      nX:X  a  M{   e   gg)a  
Check each artist has expected line colors and face colors

Parameters
----------
collections : list-like
    list or collection of target artist
linecolors : list-like which has the same length as collections
    list of expected line colors
facecolors : list-like which has the same length as collections
    list of expected face colors
mapping : Series
    Series used for color grouping key
    used for andrew_curves, parallel_coordinates, radviz test
r   )rE   )r3   LineCollectionPolyCollection)Line2DNTr!   )
matplotlibrE   r4   r3   rJ   rK   matplotlib.linesrL   ColorConverterrH   r$   r%   r5   	get_colorto_rgbatupleget_edgecolorget_facecolornpndarray)r7   
linecolors
facecolorsmappingrE   r3   rJ   rK   rL   convr8   colorresultexpecteds                 r   _check_colorsr^      s     " 
 (  D+G@J#$6c+&67J;3z?222ELE%((*f-EN#CDDu224Q78,,.||E*H%%% F +G@J#$6c+&67J;3z?222ELE%,,,,.q1,,.&"**--v||E*H%%% F r   c                   [        U 5      (       d  U R                  5       U:X  d   egU  Vs/ s H  o"R                  5       PM     nn[        U5      [        U5      :X  d   e[        X1SS9 H  u  pEXE:X  a  M   e   gs  snf )z
Check each text has expected labels

Parameters
----------
texts : matplotlib Text object, or its list-like
    target text, or its list
expected : str or list-like which has the same length as texts
    expected text label, or its list
Tr!   N)r   get_textr$   r%   )textsr]   tr   labeles         r   r   r      st     ~~8+++(-.1**,.6{c(m+++FT:HE:: ; /s   A<c                ,   SSK Jn  [        U 5      n U  GH|  nUc  Ub  [        UR                  R                  5       U5      (       a  UR                  5       nO UR                  5       UR                  SS9-   nU HU  nUb%  [        R                  " UR                  5       U5        Uc  M0  [        R                  " UR                  5       U5        MW     Uc  Uc  M  [        UR                  R                  5       U5      (       a  UR                  5       nO UR                  5       UR                  SS9-   nU HU  nUb%  [        R                  " UR                  5       U5        Uc  M0  [        R                  " UR                  5       U5        MW     GM     g)a/  
Check each axes has expected tick properties

Parameters
----------
axes : matplotlib Axes object, or its list-like
xlabelsize : number
    expected xticks font size
xrot : number
    expected xticks rotation
ylabelsize : number
    expected yticks font size
yrot : number
    expected yticks rotation
r   )NullFormatterNT)minor)matplotlib.tickerrf   r   r5   xaxisget_minor_formatterget_xticklabelsr'   r(   get_fontsizeget_rotationyaxisget_yticklabels)	r   
xlabelsizexrot
ylabelsizeyrotrf   r   r   rc   s	            r   _check_ticks_propsrt      sW     0D!D!T%5"((668-HH ++-++-0B0B0B0NN)**5+=+=+?L#**5+=+=+?F	   !T%5"((668-HH++-++-0B0B0B0NN)**5+=+=+?L#**5+=+=+?F	  + r   c                    [        U 5      n U  HC  nUR                  R                  5       U:X  d   eUR                  R                  5       U:X  a  MC   e   g)z
Check each axes has expected scales

Parameters
----------
axes : matplotlib Axes object, or its list-like
xaxis : {'linear', 'log'}
    expected xaxis scale
yaxis : {'linear', 'log'}
    expected yaxis scale
N)r   ri   	get_scalern   )r   ri   rn   r   s       r   _check_ax_scalesrw   	  sN     D!Dxx!!#u,,,xx!!#u,,, r   c                l   SSK Jn  Uc  Sn[        U 5      nUb9  [        U5      U:X  d   eU H"  n[        UR	                  5       5      S:  a  M"   e   Ub  [        5       n[        5       nU" U 5       HO  nUR                  5       R                  5       n	UR                  U	S   S   5        UR                  U	S   S   5        MQ     [        U5      [        U5      4n
X:X  d   e[        R                  " US   R                  R                  5       [        R                  " U[        R                  S95        g)an  
Check expected number of axes is drawn in expected layout

Parameters
----------
axes : matplotlib Axes object, or its list-like
axes_num : number
    expected number of axes. Unnecessary axes should be set to
    invisible.
layout : tuple
    expected layout, (expected number of rows , columns)
figsize : tuple
    expected figsize. default is matplotlib default
r   flatten_axesN)g@g333333@   )dtype)!pandas.plotting._matplotlib.toolsrz   r   r$   get_childrensetget_position
get_pointsaddr'   assert_numpy_array_equalfigureget_size_inchesrU   arrayfloat64)r   axes_numlayoutfigsizerz   visible_axesr   x_sety_setpointsr\   s              r   _check_axes_shaper     s    ?#D)L< H,,,Br()A---  t$B__&113FIIfQil#IIfQil#	 %
 e*c%j)Q..0


+r   c                |    SSK Jn  U" U 5      nU Vs/ s H  o3R                  5       (       d  M  UPM     n nU $ s  snf )zo
Flatten axes, and filter only visible

Parameters
----------
axes : matplotlib Axes object, or its list-like

r   ry   )r}   rz   r6   )r   rz   axes_ndarrayr   s       r   r   r   G  s6     ?%L%:2)9BD:K ;s   99c                    [        U 5      n U  H^  nUR                  nSnSnU H7  n[        USS5      n[        USS5      n	U(       a  US-  nU	(       d  M2  US-  nM9     X:X  d   eX&:X  a  M^   e   g)z
Check axes has expected number of errorbars

Parameters
----------
axes : matplotlib Axes object, or its list-like
xerr : number
    expected number of x errorbar
yerr : number
    expected number of y errorbar
r   has_xerrFhas_yerrr{   N)r   
containersgetattr)
r   xerryerrr   r   
xerr_count
yerr_countcr   r   s
             r   _check_has_errorbarsr   W  s     D!D]]


Aq*e4Hq*e4Ha
xa
  !!!!!! r   c                   SSK Jn  [        U[        S.nUc`  Uc  Sn[	        XU   5      (       d   eUS:X  a?  [	        U R
                  U5      (       d   e[	        U R                  [        5      (       d   eggUc%  [        U 5       H  n[	        Xd5      (       a  M   e   g[	        U [        5      (       d   e[        U R                  5       5      [        U5      :X  d   eU R                  5        H  u  px[	        XU   5      (       d   eUS:X  a!  U(       a  UR                  5       U:X  d   eM?  MA  US:X  ag  U(       a   UR
                  R                  5       U:X  d   e[	        UR
                  U5      (       d   e[	        UR                  [        5      (       d   eM  US:X  a5  US   S   n	U	R                  n
U(       a  U
R                  5       U:X  d   eM  M  [        e   g)	a  
Check box returned type is correct

Parameters
----------
returned : object to be tested, returned from boxplot
return_type : str
    return_type passed to boxplot
expected_keys : list-like, optional
    group labels in subplot case. If not passed,
    the function checks assuming boxplot uses single ax
check_ax_title : bool
    Whether to check the ax.title is the same as expected_key
    Intended to be checked by calling from ``boxplot``.
    Normal ``plot`` doesn't attach ``ax.title``, it must be disabled.
r   r   )rB   r   bothNrB   r   r   medians)matplotlib.axesr	   rB   rR   r5   r   linesr   r   sortedkeysitems	get_titler   AssertionError)returnedreturn_typeexpected_keyscheck_ax_titler	   typesrkeyvalueliner   s              r   _check_box_return_typer   s  s   & %47E K(+$67777& hkk40000hnnd3333 !
 %h/!!**** 0(F++++hmmo&&*????"..*JCe;%78888f$! ??,333 "&! 88--/3666!%((D1111!%++t4444&Y'*yy!>>+s222 " %$# +r   c                $  ^ SS K mU4S jnUc  0 nSnU GH  nTR                  R                  SS[        U5      -  U5        US-  nTR	                  SSS9  U R
                  " SSU0UD6  U" 5       (       a   eTR                  R                  5         TR                  R                  SS[        U5      -  U5        US-  nTR	                  SS	S9  U R
                  " SUSS
.UD6  U" 5       (       a   eTR                  R                  5         US;  d  GM  TR                  R                  SS[        U5      -  U5        US-  nTR	                  SS	S9  U R
                  " SSU0UD6  U" 5       (       d   eTR                  R                  5         TR                  R                  SS[        U5      -  U5        US-  nTR	                  SSS9  U R
                  " SUS	S
.UD6  U" 5       (       d   eTR                  R                  5         GM     g )Nr   c                 4  > TR                   R                  5       R                  R                  5       n TR                   R                  5       R                  R                  5       n[        S U  5       5      n[        S U 5       5      nU=(       a    U(       + $ )Nc              3  ^   #    U  H#  oR                   R                  5       (       + v   M%     g 7fr@   gridliner6   .0gs     r   	<genexpr>;_check_grid_settings.<locals>.is_grid_on.<locals>.<genexpr>  !     @Azz--///   +-c              3  ^   #    U  H#  oR                   R                  5       (       + v   M%     g 7fr@   r   r   s     r   r   r     r   r   )pyplotgcari   get_major_ticksrn   all)xticksyticksxoffyoffmpls       r   
is_grid_on(_check_grid_settings.<locals>.is_grid_on  sn    !''779!''779@@@@@@MT""r   r{      r   F)gridkindT)r   r   )piehexbinscatter )rM   r   subplotr$   rcplotclf)objkindskwsr   spndxr   r   s         @r   _check_grid_settingsr     s    # {E

1a#e*ne4
vE""d"c"<<



1a#e*ne4
vD!.d.#.<<

33JJq!c%j.%8QJEFF6F%HH&$&#&<<<JJNNJJq!c%j.%8QJEFF6F&HH1$T1S1<<<JJNN9 r   c                <    U S    Vs/ s H  o"U   PM	     sn$ s  snf )zD
Auxiliary function for correctly unpacking cycler after MPL >= 1.5
zaxes.prop_cycler   )rcParamsfieldrG   s      r   _unpack_cyclerr     s&     ''89:9eH9:::s   c                     U R                   S   $ )Nx_shared_axesr   s    r   
get_x_axisr         ??3r   c                     U R                   S   $ )Nyr   r   s    r   
get_y_axisr     r   r   c                   SSK Jn  SSKJn  [	        U [
        [        R                  45      (       ap  [	        U [
        5      (       a  U R                  n U R                  S5       H9  nS[        U5      R                  < 3n[	        X2[        45      (       a  M4   U5       e   g S[        U 5      R                  < 3n[	        X[        [        45      (       d   U5       eg )Nr   )Artistr   zBone of 'objs' is not a matplotlib Axes instance, type encountered zoobjs is neither an ndarray of Artist instances nor a single ArtistArtist instance, tuple, or dict, 'objs' is a )matplotlib.artistr   r   r	   r5   r   rU   rV   _valuesreshapetype__name__rB   rR   )objsr   r	   elmsgs        r   "assert_is_valid_plot_return_objectr     s    ($$,--dF##<<D,,r"B$$(H$5$5#8:  b,//44/ #BDz""%' 	
 $ 566;;6r   c                    SSK Jn  U(       a  [        nO[        nSnUR	                  SUR                  5       5      nUR                  5         U" X40 UD6 H  n[        U5        M     U$ )a{  
Create plot and ensure that plot return object is valid.

Parameters
----------
f : func
    Plotting function.
default_axes : bool, optional
    If False (default):
        - If `ax` not in `kwargs`, then create subplot(211) and plot there
        - Create new subplot(212) and plot there as well
        - Mind special corner case for bootstrap_plot (see `_gen_two_subplots`)
    If True:
        - Simply run plotting function with kwargs provided
        - All required axes instances will be created automatically
        - It is recommended to use it when the plotting function
        creates multiple axes itself. It helps avoid warnings like
        'UserWarning: To output multiple subplots,
        the figure containing the passed axes is being cleared'
**kwargs
    Keyword arguments passed to the plotting function.

Returns
-------
Plot object returned by the last plotting.
r   Nr   )matplotlib.pyplotr   _gen_default_plot_gen_two_subplotsgetgcfr   r   )fdefault_axeskwargsplt	gen_plotsretfigs          r   _check_plot_worksr     s[    6 $%	%	
C
**Xswwy
)CGGI*6**3/ + Jr   c              +      #    U " S0 UD6v   g7f)z
Create plot in a default way.
Nr   r   r   r   r   s      r   r   r   0  s      +f+s   c              +     #    SU;  a  UR                  S5        U " S0 UD6v   U [        R                  R                  L a	  SU;  d   eOUR                  S5      US'   U " S0 UD6v   g7f)z1
Create plot on two subplots forcefully created.
r         Nr   )add_subplotpdplottingbootstrap_plotr  s      r   r   r   7  se      6
+f+BKK&&&6!!!s+t
+f+s   A'A))NT)T)r   Axes | Sequence[Axes]r=   boolreturnNone)NNN)NNNN)linearr  )r   r
  r  zSequence[Axes])r   r   r@   )r[   )r  r  )F))__doc__
__future__r   typingr   numpyrU   pandas.core.dtypes.apir   pandasr  r   pandas._testing_testingr'   collections.abcr   r   r	   r   r   r1   r9   r>   rH   r^   r   rt   rw   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>r     s    #    /   ($+0'./&.((".=&@(,G^-$)X ": ?C:%z,^;  <,)Xr   