
    bMhA                       d Z ddlmZ ddl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 erddlmZ ddlmZ d)d
Zd)dZd Zd*dZd*d+dZd Zd,dZd Zd-dZd.dZd,dZd/dZd0dZ	 d)dZ i fd Z!d1d"Z"d# Z#d$ Z$d2d&Z%d' Z&d( Z'dS )3zF
Module consolidating common testing functions for checking plotting.
    )annotations)TYPE_CHECKINGN)is_list_like)Series)SequenceAxesTc                   |r|t          d          t          |           } | D ]e}|rK|                                J t          |                                                                |           O|                                J fdS )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/test/jupyter/venv/lib/python3.11/site-packages/pandas/tests/plotting/common.py_check_legend_labelsr      s      JFNHIIID!!D + + 	+==??...r}}88::FCCCC==??****+ +    c                    |r|t          d          |r-|                                 \  }}d |D             }||k    sJ dS |                                 J dS )a  
    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 Truec                6    g | ]}|                                 S  )
get_marker).0handles     r   
<listcomp>z(_check_legend_marker.<locals>.<listcomp>@   s$    ===66$$&&===r   )r   get_legend_handles_labelsr   )r   expected_markersr   handles_markerss         r   _check_legend_markerr#   /   s      K$,IJJJ '1133
==W===*******}}&&&&&r   c                v   ddl m} |                                 }|                                }t          |          t          |          k    sJ t	          ||          D ]B\  }}|                                }|                                }t          j        ||           C|                    d           dS )z
    Check each axes has identical lines

    Parameters
    ----------
    xp : matplotlib Axes object
    rs : matplotlib Axes object
    r   Nall)	matplotlib.pyplotpyplot	get_lineslenzip
get_xydatatmassert_almost_equalclose)	xprspltxp_linesrs_linesxplrslxpdatarsdatas	            r   _check_datar8   F   s     $#####||~~H||~~Hx==CMM))))(++ / /S!!!!
vv....IIer   c                    ddl m} t          | |          st          |           s| g} | D ]}|                                |k    sJ dS )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.collectionsr:   
isinstancer   get_visible)collectionsr   r:   patchs       r   _check_visibler@   ]   sw     211111k:.. $|K7P7P $"m . .  ""g-----. .r   r   Axes | Sequence[Axes]filledboolreturnNonec                \    t          |           } | D ]}|j        D ]}|j        |k    sJ dS )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   rB   r   r?   s       r   _check_patches_all_filledrI   q   sV     D!!D ( (Z 	( 	(E:'''''	(( (r   c                    |                                  }t          t          ||                    fd| j        D             S )Nc                     g | ]
}|         S r   r   )r   vmappeds     r   r   z&_get_colors_mapped.<locals>.<listcomp>   s    ---!F1I---r   )uniquedictr*   values)seriescolorsrN   rM   s      @r   _get_colors_mappedrS      sE    ]]__F #ff%%&&F----v}----r   c                &   ddl m} ddlm}m}m} ddlm} |j        }	||'t          ||          }|dt          |                    }t          |           t          |          k    sJ t          | |          D ]\  }
}t          |
|          r*|
                                }|	                    |          }nNt          |
||f          r(t          |
                                d                   }n|
                                }|	                    |          }||k    sJ ||'t          ||          }|dt          |                    }t          |           t          |          k    sJ t          | |          D ]\  }
}t          |
|          r|
                                d         }n|
                                }t          |t$          j                  rt          |          }|	                    |          }||k    sJ dS dS )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   )rR   )r:   LineCollectionPolyCollection)Line2DN)
matplotlibrR   r;   r:   rU   rV   matplotlib.linesrW   ColorConverterrS   r)   r*   r<   	get_colorto_rgbatupleget_edgecolorget_facecolornpndarray)r>   
linecolors
facecolorsmappingrR   r:   rU   rV   rW   convr?   colorresultexpecteds                 r   _check_colorsri      st     "!!!!!         
 (''''' D+GZ@@J#$6c+&6&6$67J;3z??2222Z88 	& 	&LE5%(( /**f--ENN#CDD /u2244Q788,,..||E**HX%%%%%+GZ@@J#$6c+&6&6$67J;3z??2222Z88 	& 	&LE5%,, /,,..q1,,..&"*-- 'v||E**HX%%%%%# 	& 	&r   c                    t          |           s|                                 |k    sJ dS d | D             }t          |          t          |          k    sJ t          ||          D ]\  }}||k    sJ dS )a  
    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
    c                6    g | ]}|                                 S r   )get_text)r   ts     r   r   z&_check_text_labels.<locals>.<listcomp>   s     ...1!**,,...r   N)r   rl   r)   r*   )textsrh   r   labeles        r   r   r      s      ~~8++++++.....6{{c(mm++++FH-- 	 	HE1A:::::	 	r   c                F   ddl m} t          |           } | D ]}||t          |j                                        |          r|                                }n+|                                |                    d          z   }|D ]T}|'t          j        |	                                |           |'t          j        |
                                |           U||t          |j                                        |          r|                                }n+|                                |                    d          z   }|D ]T}|'t          j        |	                                |           |'t          j        |
                                |           UdS )ac  
    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.tickerrr   r   r<   xaxisget_minor_formatterget_xticklabelsr,   r-   get_fontsizeget_rotationyaxisget_yticklabels)	r   
xlabelsizexrot
ylabelsizeyrotrr   r   r   ro   s	            r   _check_ticks_propsr      s     0/////D!!D G G!T%5"(6688-HH O ++--++--0B0B0B0N0NN G G)*5+=+=+?+?LLL#*5+=+=+?+?FFF!T%5"(6688-HH O++--++--0B0B0B0N0NN G G)*5+=+=+?+?LLL#*5+=+=+?+?FFF3G Gr   linearc                    t          |           } | D ]@}|j                                        |k    sJ |j                                        |k    sJ AdS )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   ru   	get_scalerz   )r   ru   rz   r   s       r   _check_ax_scalesr     sk     D!!D - -x!!##u,,,,x!!##u,,,,,- -r   c                   ddl m} |d}t          |           }|At          |          |k    sJ |D ])}t          |                                          dk    sJ *|t                      }t                      } ||           D ]j}|                                                                }	|                    |	d         d                    |                    |	d         d                    kt          |          t          |          f}
|
|k    sJ t          j
        |d         j                                        t          j        |t          j                             dS )a  
    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.toolsr   r   r)   get_childrensetget_position
get_pointsaddr,   assert_numpy_array_equalfigureget_size_inchesr`   arrayfloat64)r   axes_numlayoutfigsizer   visible_axesr   x_sety_setpointsrg   s              r   _check_axes_shaper     st    ?>>>>>#D))L<  H,,,, 	. 	.Br(())A-----,t$$ 	$ 	$B__&&1133FIIfQil###IIfQil####e**c%jj)Q..00

+++    r   Sequence[Axes]c                @    ddl m}  ||           }d |D             } | S )z
    Flatten axes, and filter only visible

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

    r   r   c                :    g | ]}|                                 |S r   )r=   )r   r   s     r   r   z$_flatten_visible.<locals>.<listcomp>W  s'    :::2)9)9:B:::r   )r   r   )r   r   axes_ndarrays      r   r   r   K  s=     ?>>>>><%%L:::::DKr   c                    t          |           } | D ]R}|j        }d}d}|D ]2}t          |dd          }t          |dd          }	|r|dz  }|	r|dz  }3||k    sJ ||k    sJ SdS )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   [  s     D!!D " "]


 	  	 Aq*e44Hq*e44H  a
  a
z!!!!z!!!!!" "r   c                   ddl m} t          |t          d}|Y|d}t	          | ||                   sJ |dk    r3t	          | j        |          sJ t	          | j        t                    sJ dS dS |&t          |           D ]}t	          ||          sJ dS t	          | t                    sJ t          | 
                                          t          |          k    sJ |                                 D ]\  }}t	          |||                   sJ |dk    r|r|                                |k    sJ @|dk    rU|r|j                                        |k    sJ t	          |j        |          sJ t	          |j        t                    sJ |dk    r2|d         d         }	|	j        }
|r|
                                |k    sJ t          dS )	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   )rO   r   bothNrO   r   r   medians)matplotlib.axesr	   rO   r]   r<   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   w  s7   & %$$$$$477E K(E+$677777&  hk400000hnd33333 ! 33 %h// + +!!T******F(F+++++hmmoo&&&*?*?????"..** 	% 	%JCeU;%788888f$$! 4 ??,,3333&&! 7 8--//36666!%(D11111!%+t444444&&Y'*y! 3>>++s2222$$#	% 	%r   c                   dd l fd}d}|D ]}j                            ddt          |          z  |           |dz  }                    dd            | j        dd|i|  |            rJ j                                         j                            ddt          |          z  |           |dz  }                    dd	            | j        d|dd
|  |            rJ j                                         |dvrj                            ddt          |          z  |           |dz  }                    dd	            | j        dd|i|  |            sJ j                                         j                            ddt          |          z  |           |dz  }                    dd            | j        d|d	d
|  |            sJ j                                         d S )Nr   c                 2   j                                         j                                        } j                                         j                                        }t          d | D                       }t          d |D                       }|o| S )Nc              3  J   K   | ]}|j                                          V  d S Ngridliner=   r   gs     r   	<genexpr>z;_check_grid_settings.<locals>.is_grid_on.<locals>.<genexpr>  3      @@Aqz--///@@@@@@r   c              3  J   K   | ]}|j                                          V  d S r   r   r   s     r   r   z;_check_grid_settings.<locals>.is_grid_on.<locals>.<genexpr>  r   r   )r'   gcaru   get_major_ticksrz   r%   )xticksyticksxoffyoffmpls       r   
is_grid_onz(_check_grid_settings.<locals>.is_grid_on  s    !!'7799!!'7799@@@@@@@@@@@@@@MT""r   r      r   F)gridkindT)r   r   )piehexbinscatterr   )rX   r'   subplotr)   rcplotclf)objkindskwsr   spndxr   r   s         @r   _check_grid_settingsr     sk    # # # # # E  
1a#e**ne444
vE"""""d"c""":<<

1a#e**ne444
vD!!!.d..#...:<<
333Jq!c%jj.%888QJEFF6F%%%CH&&$&#&&&:<<JNNJq!c%jj.%888QJEFF6F&&&CH1$T11S111:<<JNN9 r   rf   c                ,    fd| d         D             S )zL
    Auxiliary function for correctly unpacking cycler after MPL >= 1.5
    c                     g | ]
}|         S r   r   )r   rL   fields     r   r   z"_unpack_cycler.<locals>.<listcomp>  s    :::AeH:::r   zaxes.prop_cycler   )rcParamsr   s    `r   _unpack_cyclerr     s%     ;:::h'89::::r   c                    | j         d         S )Nx_shared_axesr   s    r   
get_x_axisr         ?3r   c                    | j         d         S )Nyr   r   s    r   
get_y_axisr     r   r   Fc                V   ddl m} |rt          }nt          }d}	 |                    d|                                          }|                                  || |fi |D ]}t          j        |           	 |	                    |           n# |	                    |           w xY w|S )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   )
r&   r'   _gen_default_plot_gen_two_subplotsgetgcfr   r,   "assert_is_valid_plot_return_objectr.   )fdefault_axeskwargsr1   	gen_plotsretfigs          r   _check_plot_worksr     s    6 $##### &%		%	
Cjj37799--			9Q..v.. 	7 	7C1#6666	7 			#		#Js   AB B&c              +     K    | di |V  dS )z'
    Create plot in a default way.
    Nr   r   r   r   r   s      r   r   r      s&       !++f++r   c              +     K   d|vr|                     d            | di |V  | t          j        j        u rd|vsJ n|                     d          |d<    | di |V  dS )z9
    Create plot on two subplots forcefully created.
    r         Nr   )add_subplotpdplottingbootstrap_plotr   s      r   r   r   '  s       6
!++f++BK&&&6!!!!!s++t
!++f++r   )NT)T)r   rA   rB   rC   rD   rE   )NNN)NNNN)r   r   )r   rA   rD   r   )r   r   )rf   )F)(__doc__
__future__r   typingr   numpyr`   pandas.core.dtypes.apir   pandasr  r   pandas._testing_testingr,   collections.abcr   r   r	   r   r#   r8   r@   rI   rS   ri   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>r     sT    # " " " " "                 / / / / / /                 %(((((($$$$$$+ + + +0' ' ' '.  .. . . .(( ( ( ( (". . .=& =& =& =&@  (,G ,G ,G ,G^- - - -$) ) ) )X    " " " ": ?C:% :% :% :%z *, * * * *Z; ; ; ;          - - - -`      r   