
    OwgA                       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d%dZ	 ddZ i fdZ!d&dZ"d Z#d Z$d'dZ%d Z&d Z'y)(zF
Module consolidating common testing functions for checking plotting.
    )annotations)TYPE_CHECKINGN)is_list_like)Series)SequenceAxesc                    |r|t        d      t        |       } | D ]Q  }|r;|j                         J t        |j                         j	                         |       @|j                         QJ  y)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       S/var/www/horilla/myenv/lib/python3.12/site-packages/pandas/tests/plotting/common.py_check_legend_labelsr      sp     FNHIID!D +==?...r}}88:FC==?***+    c                    |r|t        d      |r8| j                         \  }}|D cg c]  }|j                          }}||k(  sJ y| j                         J yc c}w )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 True)r   get_legend_handles_labels
get_markerr   )r   expected_markersr   handles_handlemarkerss          r   _check_legend_markerr   /   sp     $,IJJ113
5<=66$$&==****}}&&& >s   Ac                8   ddl m} | j                         }|j                         }t        |      t        |      k(  sJ t	        ||      D ];  \  }}|j                         }|j                         }t        j                  ||       = |j                  d       y)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_datar4   F   s     $||~H||~Hx=CM)))(+ /S!!
vv./
 IIer   c                |    ddl m} t        | |      st        |       s| g} | D ]  }|j	                         |k(  rJ  y)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.collectionsr6   
isinstancer   get_visible)collectionsr   r6   patchs       r   _check_visibler<   ]   sE     2k:.|K7P"m .  "g---.r   c                l    t        |       } | D ]$  }|j                  D ]  }|j                  |k(  rJ  & y)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   r;   s       r   _check_patches_all_filledrA   q   sB     D!D (ZZ 	(E::'''	((r   c                    | j                         }t        t        ||            }| j                  D cg c]  }||   	 c}S c c}w N)uniquedictr&   values)seriescolorsrD   mappedvs        r   _get_colors_mappedrK      s<    ]]_F #ff%&F%}}-!F1I---s   Ac                R   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"|
j                         }|	j                  |      }n;t        |
||f      rt        |
j!                         d         }n|
j!                         }|	j                  |      }||k(  rJ  ||t        ||      }|dt        |        }t        |       t        |      k(  sJ t        | |      D ]r  \  }
}t        |
|      r|
j#                         d   }n|
j#                         }t        |t$        j&                        rt        |      }|	j                  |      }||k(  rrJ  yy)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   )rH   )r6   LineCollectionPolyCollection)Line2DN)
matplotlibrH   r7   r6   rM   rN   matplotlib.linesrO   ColorConverterrK   r%   r&   r8   	get_colorto_rgbatupleget_edgecolorget_facecolornpndarray)r:   
linecolors
facecolorsmappingrH   r6   rM   rN   rO   convr;   colorresultexpecteds                 r   _check_colorsra      s     " 
 (  D+GZ@J#$6c+&67J;3z?222Z8 	&LE5%(*f-ENN#CDu224Q78,,.||E*HX%%%	& +GZ@J#$6c+&67J;3z?222Z8 	&LE5%,,,.q1,,.&"**-v||E*HX%%%	& r   c                    t        |       s| j                         |k(  sJ y| D cg c]  }|j                          }}t        |      t        |      k(  sJ t        ||      D ]  \  }}||k(  rJ  yc c}w )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
    N)r   get_textr%   r&   )textsr`   tr   labeles         r   r   r      s{     ~~8+++(-.1!**,..6{c(m+++FH- 	HE1A::	 /s   A4c                   ddl m} t        |       } | D ]d  }||t        |j                  j                         |      r|j                         }n#|j                         |j                  d      z   }|D ]O  }|$t        j                  |j                         |       |,t        j                  |j                         |       Q ||t        |j                  j                         |      r|j                         }n#|j                         |j                  d      z   }|D ]O  }|$t        j                  |j                         |       |,t        j                  |j                         |       Q g y)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.tickerri   r   r8   xaxisget_minor_formatterget_xticklabelsr(   r)   get_fontsizeget_rotationyaxisget_yticklabels)	r   
xlabelsizexrot
ylabelsizeyrotri   r   r   rf   s	            r   _check_ticks_propsrw      sf     0D!D G!T%5"((668-H ++-++-0B0B0B0NN G)**5+=+=+?L#**5+=+=+?F	G !T%5"((668-H++-++-0B0B0B0NN G)**5+=+=+?L#**5+=+=+?F	G+Gr   c                    t        |       } | D ]@  }|j                  j                         |k(  sJ |j                  j                         |k(  r@J  y)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   rl   	get_scalerq   )r   rl   rq   r   s       r   _check_ax_scalesrz     sS     D!D -xx!!#u,,,xx!!#u,,,-r   c                \   ddl m} |d}t        |       }|5t        |      |k(  sJ |D ]   }t        |j	                               dkD  r J  |t               }t               } ||       D ]N  }|j                         j                         }	|j                  |	d   d          |j                  |	d   d          P t        |      t        |      f}
|
|k(  sJ t        j                  |d   j                  j                         t        j                  |t        j                               y)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_inchesrX   arrayfloat64)r   axes_numlayoutfigsizer}   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                l    ddl m}  ||       }|D cg c]  }|j                         s| } }| S c c}w )z
    Flatten axes, and filter only visible

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

    r   r|   )r   r}   r9   )r   r}   axes_ndarrayr   s       r   r   r   K  s7     ?%L%:2)9B:D:K ;s   11c                    t        |       } | D ]P  }|j                  }d}d}|D ]+  }t        |dd      }t        |dd      }	|r|dz  }|	s'|dz  }- ||k(  sJ ||k(  rPJ  y)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4Hq*e4Ha
a
	  z!!!z!!!"r   c                6   ddl m} t        |t        d}|P|d}t	        | ||         sJ |dk(  r5t	        | j
                  |      sJ t	        | j                  t              sJ yy|t        |       D ]  }t	        ||      rJ  yt	        | t              sJ t        | j                               t        |      k(  sJ | j                         D ]  \  }}t	        |||         sJ |dk(  r|s|j                         |k(  r3J |dk(  rV|r|j
                  j                         |k(  sJ t	        |j
                  |      sJ t	        |j                  t              rJ |dk(  r-|d   d   }	|	j                  }
|s|
j                         |k(  rJ t         y)	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   )rE   r   bothNrE   r   r   medians)matplotlib.axesr	   rE   rU   r8   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  s   & %47E K(E+$6777& hkk4000hnnd333 !
 %h/ +!!T***+(F+++hmmo&&*????"..* 	%JCeU;%7888f$! ??,333&! 88--/3666!%((D111!%++t444&Y'*yy!>>+s222$$#	%r   c                   dd l fd}d}|D ]  }j                  j                  ddt        |      z  |       |dz  }j	                  dd        | j
                  dd|i|  |       rJ j                  j                          j                  j                  ddt        |      z  |       |dz  }j	                  dd	        | j
                  d|dd
|  |       rJ j                  j                          |dvsj                  j                  ddt        |      z  |       |dz  }j	                  dd	        | j
                  dd|i|  |       sJ j                  j                          j                  j                  ddt        |      z  |       |dz  }j	                  dd        | j
                  d|d	d
|  |       sJ j                  j                           y )Nr   c                 "   j                   j                         j                  j                         } j                   j                         j                  j                         }t        d | D              }t        d |D              }|xr | S )Nc              3  R   K   | ]  }|j                   j                           ! y wrC   gridliner9   .0gs     r   	<genexpr>z;_check_grid_settings.<locals>.is_grid_on.<locals>.<genexpr>        @Aqzz--//@   %'c              3  R   K   | ]  }|j                   j                           ! y wrC   r   r   s     r   r   z;_check_grid_settings.<locals>.is_grid_on.<locals>.<genexpr>  r   r   )r#   gcarl   get_major_ticksrq   r!   )xticksyticksxoffyoffmpls       r   
is_grid_onz(_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 )rP   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%CHH&$&#&<<JJNNJJq!c%j.%8QJEFF6F&CHH1$T1S1<<JJNN9r   c                8    | d   D cg c]  }||   	 c}S c c}w )zL
    Auxiliary function for correctly unpacking cycler after MPL >= 1.5
    zaxes.prop_cycler   )rcParamsfieldrJ   s      r   _unpack_cyclerr     s"     ''89:AeH:::s   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   c                .   ddl m} |rt        }nt        }d}	 |j	                  d|j                               }|j                           || |fi |D ]  }t        j                  |        	 |j                  |       |S # |j                         w xY w)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kwargsr-   	gen_plotsretfigs          r   _check_plot_worksr     s    6 $%	%	
Cjj3779-	Q.v. 	7C11#6	7 			#J 			#s   AB Bc              +      K    | di | yw)z'
    Create plot in a default way.
    Nr   r   r   r   r   s      r   r   r      s      +f+s   c              +     K   d|vr|j                  d        | di | | t        j                  j                  u rd|vsJ |j                  d      |d<    | di | yw)z9
    Create plot on two subplots forcefully created.
    r         Nr   )add_subplotpdplottingbootstrap_plotr   s      r   r   r   '  sf      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^   )F)(__doc__
__future__r   typingr   numpyrX   pandas.core.dtypes.apir   pandasr   r   pandas._testing_testingr(   collections.abcr   r   r	   r   r   r4   r<   rA   rK   ra   r   rw   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>r
     s    #    /   ($+0'...((".=&@(,G^-$)X ": ?C:%z *, *Z;  -`r   