
    dJ                        d Z ddlmZ ddlmZmZ ddlZddlm	Z	 ddl
mc m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 ej         G d	 d
                      ZddZd Zd ZdS )zF
Module consolidating common testing functions for checking plotting.
    )annotations)TYPE_CHECKINGSequenceN)cache_readonly)is_list_like)SeriesAxesc                      e Zd ZdZd Zd Zed             Zed             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 Zd Zd*dZ	 d$dZi fdZd+d!Zd" Zd# ZdS ),TestPlotBasezE
    This is a common base class used for various plotting tests
    c                6    dd l }|                                 d S Nr   )
matplotlib
rcdefaults)selfmpls     X/var/www/html/t/fyr/venv311/lib/python3.11/site-packages/pandas/tests/plotting/common.pysetup_methodzTestPlotBase.setup_method!   s$            c                ,    t          j                     d S N)tmclose)r   s    r   teardown_methodzTestPlotBase.teardown_method&   s    





r   c                    dd l m} |S r   )matplotlib.pyplotpyplot)r   plts     r   r   zTestPlotBase.plt)   s    ''''''
r   c                    ddl m} |j        S )Nr   )colors)r   r    colorConverter)r   r    s     r   colorconverterzTestPlotBase.colorconverter/   s    %%%%%%$$r   NTc                2   |r|t          d          |                     |          }|D ]k}|rQ|                                J |                     |                                                                |           U|                                J ldS )aQ  
        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)r   axeslabelsvisibleaxs        r   _check_legend_labelsz!TestPlotBase._check_legend_labels5   s      	NLMMM$$T** 	/ 	/B /}}222''(A(A(C(CVLLLL}}....	/ 	/r   c                    |r|t          d          |r-|                                \  }}d |D             }||k    sJ dS |                                J dS )aB  
        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>z5TestPlotBase._check_legend_marker.<locals>.<listcomp>]   s$    AAAvv((**AAAr   )r$   get_legend_handles_labelsr&   )r   r,   expected_markersr+   handles_markerss          r   _check_legend_markerz!TestPlotBase._check_legend_markerL   s      	O(0MNNN 	+5577JGQAAAAAG.......==??*****r   c                f   |                                 }|                                 }t          |          t          |          k    sJ t          ||          D ]B\  }}|                                }|                                }t	          j        ||           Ct	          j                     dS )z
        Check each axes has identical lines

        Parameters
        ----------
        xp : matplotlib Axes object
        rs : matplotlib Axes object
        N)	get_lineslenzip
get_xydatar   assert_almost_equalr   )	r   xprsxp_linesrs_linesxplrslxpdatarsdatas	            r   _check_datazTestPlotBase._check_datab   s     <<>><<>>8}}H----Hh// 	3 	3HC^^%%F^^%%F"662222





r   c                    ddl m} t          ||          st          |          s|g}|D ]}|                                |k    sJ dS )a   
        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.collectionsrK   
isinstancer   get_visible)r   collectionsr+   rK   patchs        r   _check_visiblezTestPlotBase._check_visiblev   sw     	655555+z22 	(<;T;T 	(&-K  	2 	2E$$&&'11111	2 	2r   r)   Axes | Sequence[Axes]filledboolreturnNonec                h    |                      |          }|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   r)   rS   r,   rP   s        r   _check_patches_all_filledz&TestPlotBase._check_patches_all_filled   s\     $$T** 	, 	,B , ,zV+++++,	, 	,r   c                    |                                 }t          t          ||                    fd|j        D             S )Nc                     g | ]
}|         S r0   r0   )r2   vmappeds     r   r4   z3TestPlotBase._get_colors_mapped.<locals>.<listcomp>   s    111aq	111r   )uniquedictr>   values)r   seriesr    r_   r^   s       @r   _get_colors_mappedzTestPlotBase._get_colors_mapped   sE     c&&))**11116=1111r   c                2   ddl m}m}m} ddlm} | j        }	||-|                     ||          }|dt          |                   }t          |          t          |          k    sJ t          ||          D ]\  }
}t          |
|          r*|
                                }|	                    |          }nNt          |
||f          r(t          |
                                d                   }n|
                                }|	                    |          }||k    sJ ||-|                     ||          }|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 )a3  
        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   )rK   LineCollectionPolyCollection)Line2DN)rL   rK   re   rf   matplotlib.linesrg   r"   rc   r=   r>   rM   	get_colorto_rgbatupleget_edgecolorget_facecolornpndarray)r   rO   
linecolors
facecolorsmappingrK   re   rf   rg   convrP   colorresultexpecteds                 r   _check_colorszTestPlotBase._check_colors   sl   $	
 	
 	
 	
 	
 	
 	
 	
 	
 	

 	,+++++"!"!44WjII
'(:#k*:*:(:;
{##s:6666 #K < < * *ueV,, 3"__..F!\\&11FF'GHH 3"5#6#6#8#8#;<<FF"0022F<<..)))))!"!44WjII
'(:#k*:*:(:;
{##s:6666 #K < < * *ueZ00 3"002215FF"0022Ffbj11 +"6]]F<<..)))))# "!* *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 r0   )get_text)r2   ts     r   r4   z3TestPlotBase._check_text_labels.<locals>.<listcomp>   s     222qajjll222r   N)r   rz   r=   r>   )r   textsrv   r*   labeles         r   r'   zTestPlotBase._check_text_labels   s     E"" 	">>##x//////22E222Fv;;#h--////11 " "qzzzzz" "r   c                R   ddl m} |                     |          }|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 )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.tickerr   r%   rM   xaxisget_minor_formatterget_xticklabelsr   r@   get_fontsizeget_rotationyaxisget_yticklabels)
r   r)   
xlabelsizexrot
ylabelsizeyrotr   r,   r*   r}   s
             r   _check_ticks_propszTestPlotBase._check_ticks_props   s   $ 	433333$$T** 	K 	KB%)9bh::<<mLL S  //11FF//11B4F4FT4F4R4RRF# K KE!-.u/A/A/C/CZPPP'.u/A/A/C/CTJJJ%)9bh::<<mLL S//11FF//11B4F4FT4F4R4RRF# K KE!-.u/A/A/C/CZPPP'.u/A/A/C/CTJJJ3	K 	Kr   linearc                    |                      |          }|D ]@}|j                                        |k    sJ |j                                        |k    sJ AdS )a  
        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%   r   	get_scaler   )r   r)   r   r   r,   s        r   _check_ax_scaleszTestPlotBase._check_ax_scales%  sq     $$T** 	1 	1B8%%''500008%%''500000	1 	1r   c                   ddl m} |d}|                     |          }|At          |          |k    sJ |D ])}t          |                                          dk    sJ *|&|                      ||                    }||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_get_axes_layoutr   assert_numpy_array_equalfigureget_size_inchesrn   arrayfloat64)	r   r)   axes_numlayoutfigsizer   visible_axesr,   ru   s	            r   _check_axes_shapezTestPlotBase._check_axes_shape6  s    	CBBBBB? G,,T22|$$0000" 2 22??,,--11111**<<+=+=>>FV####
#O"2244HWBJ///	
 	
 	
 	
 	
r   c                P   t                      }t                      }|D ]j}|                                                                }|                    |d         d                    |                    |d         d                    kt	          |          t	          |          fS )Nr      )setget_position
get_pointsaddr=   )r   r)   x_sety_setr,   pointss         r   r   zTestPlotBase._get_axes_layoutZ  s     	$ 	$B__&&1133FIIfQil###IIfQil####E

CJJ''r   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 r0   )rN   )r2   r,   s     r   r4   z1TestPlotBase._flatten_visible.<locals>.<listcomp>p  s'    666rR^^%5%56666r   )r   r   )r   r)   r   s      r   r%   zTestPlotBase._flatten_visibled  s>     	CBBBBB|D!!66T666r   r   c                    |                      |          }|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 )a  
        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   r)   xerryerrr,   r   
xerr_count
yerr_countcr   r   s              r   _check_has_errorbarsz!TestPlotBase._check_has_errorbarss  s     $$T** 	& 	&BJJJ $ $"1j%88"1j%88 $!OJ $!OJ:%%%%:%%%%%	& 	&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 |,|                     |          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 )	at  
        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	   )r`   r)   bothNr`   r   r)   medians)matplotlib.axesr
   r`   rk   rM   r,   linesr%   r   sortedkeysitems	get_titler)   AssertionError)r   returnedreturn_typeexpected_keyscheck_ax_titler
   typesrkeyvalueliner)   s               r   _check_box_return_typez#TestPlotBase._check_box_return_type  s=   & 	)(((((tU;; "$hk(:;;;;;f$$!(+t44444!(.$77777 %$77 "..x88 / /A%a......h/////(--//**f].C.CCCCC&nn.. ) )
U!%{);<<<<<&((% 8$00C7777 F**% ;$x1133s::::%eh55555%ek4888888 F** +A.D9D% 7#~~//36666((#) )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 r   gridlinerN   r2   gs     r   	<genexpr>zHTestPlotBase._check_grid_settings.<locals>.is_grid_on.<locals>.<genexpr>  3      DD1:11333DDDDDDr   c              3  J   K   | ]}|j                                          V  d S r   r   r   s     r   r   zHTestPlotBase._check_grid_settings.<locals>.is_grid_on.<locals>.<genexpr>  r   r   )r   gcar   get_major_ticksr   all)xticksyticksxoffyoffr   s       r   
is_grid_onz5TestPlotBase._check_grid_settings.<locals>.is_grid_on  s    X\\^^)99;;FX\\^^)99;;FDDVDDDDDDDDVDDDDDD&&r   r      r)   F)gridkindT)r   r   )piehexbinscatterr0   )r   r   subplotr=   rcplotclf)r   objkindskwsr   r   spndxr   s   `       r   _check_grid_settingsz!TestPlotBase._check_grid_settings  s_    	!   	' 	' 	' 	' 	'  	 	DHQCJJ666QJEFF6F&&&CH&&$&#&&&!z||###HLLNNNHQCJJ666QJEFF6F%%%CH2$U22c222!z||###HLLNNN777  AE

NE:::
vD)))**d*c***!z||###  AE

NE:::
vE***5d55555!z||###9	 	r   rt   c                ,    fd|d         D             S )zT
        Auxiliary function for correctly unpacking cycler after MPL >= 1.5
        c                     g | ]
}|         S r0   r0   )r2   r]   fields     r   r4   z/TestPlotBase._unpack_cycler.<locals>.<listcomp>  s    >>>Q%>>>r   zaxes.prop_cycler0   )r   rcParamsr   s     `r   _unpack_cyclerzTestPlotBase._unpack_cycler  s%     ?>>>(+<"=>>>>r   c                    |j         d         S )Nx_shared_axesr   r,   s     r   
get_x_axiszTestPlotBase.get_x_axis      s##r   c                    |j         d         S )Nyr   r   s     r   
get_y_axiszTestPlotBase.get_y_axis  r   r   )NT)T)r)   rR   rS   rT   rU   rV   )NNN)NNNN)r   r   )r   r   )rt   )__name__
__module____qualname____doc__r   r   r   r   r"   r-   r:   rI   rQ   rZ   rc   rw   r'   r   r   r   r   r%   r   r   r   r   r   r   r0   r   r   r   r      s          
     ^
 % % ^%
/ / / /.+ + + +,  (2 2 2 2( ;?, , , , ,$2 2 2 FJ>* >* >* >*@" " "( GK.K .K .K .K`1 1 1 1""
 "
 "
 "
H( ( (  & & & &8 IM:) :) :) :)x 46 * * * *X? ? ? ?$ $ $$ $ $ $ $r   r   Fc                   ddl m} |rt          }nt          }d}	 |                    d|                                          }|                                  || |fi |D ]}t          j        |           t          j	        d          5 }|
                    |           ddd           n# 1 swxY w Y   t          j        |           n# t          j        |           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   T)return_filelike)r   r   _gen_default_plot_gen_two_subplotsgetgcfr   r   "assert_is_valid_plot_return_objectensure_cleansavefigr   )fdefault_axeskwargsr   	gen_plotsretfigpaths           r   _check_plot_worksr    s2   6 $##### &%		%	
Cjj37799--			9Q..v.. 	7 	7C1#6666_T222 	dKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	Js0   A2C B/#C /B33C 6B37C C%c              +     K    | di |V  dS )z'
    Create plot in a default way.
    Nr0   r0   r  r  r  s      r   r  r  6  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,         Nr0   )add_subplotpdplottingbootstrap_plotr  s      r   r  r  =  s       6
!++f++BK&&&6!!!!!s++t
!++f++r   )F)r  
__future__r   typingr   r   numpyrn   pandas.util._decoratorsr   pandas.util._test_decoratorsutil_test_decoratorstdpandas.core.dtypes.apir   pandasr  r   pandas._testing_testingr   r   r
   skip_if_no_mplr   r  r  r  r0   r   r   <module>r)     s`    # " " " " "       
     2 2 2 2 2 2 ) ) ) ) ) ) ) ) ) / / / / / /                 %$$$$$$ d$ d$ d$ d$ d$ d$ d$ d$N0 0 0 0f      r   