gL iAdZddlmZddlmZddlZddlmZddl Z ddl m Z ddl m Zer ddlmZddlmZdd Zdd Zd Zdd Zdd d ZdZd!dZdZd"dZd#dZd!dZd$dZd%dZ ddZ ifdZ!d&dZ"dZ#dZ$d'dZ%dZ&dZ'y)(zF Module consolidating common testing functions for checking plotting. ) annotations) TYPE_CHECKINGN) is_list_like)Series)SequenceAxesc|r | tdt|}|D]Q}|r;|jJt|jj |@|jQJy)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)axeslabelsvisibleaxs b/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/pandas/tests/plotting/common.py_check_legend_labelsrspFNHII D !D+ ==?. .. r}}88:F C==?* ** +c|r | td|r8|j\}}|Dcgc]}|j}}||k(sJy|jJycc}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 )rexpected_markersrhandles_handlemarkerss r_check_legend_markerr/sp$,IJJ113 5<=66$$&==****}}&&&>sAc8ddlm}|j}|j}t|t|k(sJt ||D];\}}|j }|j }t j||=|jdy)z Check each axes has identical lines Parameters ---------- xp : matplotlib Axes object rs : matplotlib Axes object rNall) matplotlib.pyplotpyplot get_lineslenzip get_xydatatmassert_almost_equalclose) xprspltxp_linesrs_linesxplrslxpdatarsdatas r _check_datar4Fs$||~H||~H x=CM )) )(+/S!! vv./ IIerc|ddlm}t||st|s|g}|D]}|j |k(rJy)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) collectionsrr6patchs r_check_visibler<]sE2 k: .|K7P"m .  "g---.rclt|}|D]$}|jD]}|j|k(rJ&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 patchesfill)rfilledrr;s r_check_patches_all_filledrAqsB D !D(ZZ (E::' '' ((rc|j}tt||}|jDcgc]}|| c}Scc}wN)uniquedictr&values)seriescolorsrDmappedvs r_get_colors_mappedrKs< ]]_F#ff% &F%}} -!F1I -- -s AcRddlm}ddlm}m}m}ddlm}|j} ||t||}|dt|}t|t|k(sJt||D]\} } t| |r"| j} | j| } n;t| ||frt| j!d} n| j!} | j| } | | k(rJ||t||}|dt|}t|t|k(sJt||D]r\} } t| |r| j#d} n| j#} t| t$j&r t| } | j| } | | k(rrJyy)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)r6LineCollectionPolyCollection)Line2DN) matplotlibrHr7r6rMrNmatplotlib.linesrOColorConverterrKr%r&r8 get_colorto_rgbatuple get_edgecolor get_facecolornpndarray)r: linecolors facecolorsmappingrHr6rMrNrOconvr;colorresultexpecteds r _check_colorsras " (  D  +GZ@J#$6c+&67J;3z?222 Z8 &LE5%(*f-ENN#CDu224Q78,,.||E*HX% %% &  +GZ@J#$6c+&67J;3z?222 Z8 &LE5%,,,.q1,,.&"**-v||E*HX% %% & rct|s|j|k(sJy|Dcgc]}|j}}t|t|k(sJt||D] \}}||k(r Jycc}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)rget_textr%r&)textsr`trlabeles rrrs{  ~~8+++(-.1!**,..6{c(m+++FH- HE1A: : /sA4cddlm}t|}|D]d}||t|jj |r|j }n#|j |j dz}|D]O}|$tj|j||,tj|j|Q||t|jj |r|j}n#|j|jdz}|D]O}|$tj|j||,tj|j|Qgy)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.tickerrir r8xaxisget_minor_formatterget_xticklabelsr(r) get_fontsize get_rotationyaxisget_yticklabels) r xlabelsizexrot ylabelsizeyrotrirrrfs r_check_ticks_propsrwsf 0 D !DG  !T%5"((668-H++-++-0B0B0B0NN G)**5+=+=+?L#**5+=+=+?F  G  !T%5"((668-H++-++-0B0B0B0NN G)**5+=+=+?L#**5+=+=+?F  G+Grct|}|D]@}|jj|k(sJ|jj|k(r@Jy)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)rrlrqrs r_check_ax_scalesrz sS D !D-xx!!#u,,,xx!!#u,,,-rc\ddlm}|d}t|}|5t||k(sJ|D] }t|j dkDr J|t }t }||D]N}|j j} |j| dd|j| ddPt|t|f} | |k(sJtj|djjtj|tjy)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_childrenset get_position get_pointsaddr(assert_numpy_array_equalfigureget_size_inchesrXarrayfloat64) raxes_numlayoutfigsizer} visible_axesrx_sety_setpointsr_s r_check_axes_shapers?#D)L< H,,, .Br()A- -- .t$ $B__&113F IIfQil # IIfQil #  $ e*c%j)Q..0  +rclddlm}||}|Dcgc]}|js|}}|Scc}w)z Flatten axes, and filter only visible Parameters ---------- axes : matplotlib Axes object, or its list-like rr|)rr}r9)rr} axes_ndarrayrs rr r Ks7?%L% :2)9B :D : K ;s11ct|}|D]P}|j}d}d}|D]+}t|dd}t|dd} |r|dz }| s'|dz }-||k(sJ||k(rPJy)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 rhas_xerrFhas_yerrr~N)r containersgetattr) rxerryerrrr xerr_count yerr_countcrrs r_check_has_errorbarsr[s D !D "]]    Aq*e4Hq*e4Ha a  z!!!z!!! "rc6ddlm}t|td}|P|d}t |||sJ|dk(r5t |j |sJt |j tsJyy|t|D]}t ||rJyt |tsJt|jt|k(sJ|jD]\}}t |||sJ|dk(r|s|j|k(r3J|dk(rV|r|j j|k(sJt |j |sJt |j trJ|dk(r-|dd} | j} |s| j|k(rJty) 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. rr)rErbothNrErrmedians)matplotlib.axesr rErUr8rlinesr rsortedkeysitems get_titlerAssertionError) returned return_type expected_keyscheck_ax_titler typesrkeyvalueliners r_check_box_return_typerws&%4 7E   K(E+$6777 & hkk40 00hnnd3 33 !  %h/ +!!T*** + (F+++hmmo&&*????"..* %JCeU;%78 88f$! ??,333&! 88--/3666!%((D111!%++t444&Y'*yy!>>+s222$$# %rcddlfd}d}|D]}jjddt|z||dz }j dd|j d d|i||rJjj jjddt|z||dz }j dd |j d |dd ||rJjj |d vsjjddt|z||dz }j dd |j d d|i||sJjj jjddt|z||dz }j dd|j d |d d ||sJjj y) Nrc"jjjj}jjjj}t d|D}t d|D}|xr| S)Nc3RK|]}|jj !ywrCgridliner9.0gs r z;_check_grid_settings..is_grid_on.. @Aqzz--//@%'c3RK|]}|jj !ywrCrrs rrz;_check_grid_settings..is_grid_on..rr)r#gcarlget_major_ticksrqr!)xticksyticksxoffyoffmpls r is_grid_onz(_check_grid_settings..is_grid_onsn!''779!''779@@@@@@MT""rr~rF)gridkindT)rr)piehexbinscatter)rPr#subplotr%rcplotclf)objkindskwsrspndxrrs @r_check_grid_settingsrs# E 1a#e*ne4   vE""d"c"<  1a#e*ne4   vD!.d.#.<  3 3 JJ  q!c%j.% 8 QJE FF6F % CHH &$ &# &< < JJNN  JJ  q!c%j.% 8 QJE FF6F & CHH 1$T 1S 1< < JJNN 9rc8|dDcgc]}|| c}Scc}w)zL Auxiliary function for correctly unpacking cycler after MPL >= 1.5 zaxes.prop_cycler)rcParamsfieldrJs r_unpack_cyclerrs"''89 :AeH :: :s c |jdS)Nx _shared_axesrs r get_x_axisr ??3 rc |jdS)Nyrrs r get_y_axisrrrc .ddlm}|rt}nt}d} |j d|j }|j |||fi|D]}tj| |j||S#|jwxYw)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. rNr) r"r#_gen_default_plot_gen_two_subplotsgetgcfrr("assert_is_valid_plot_return_objectr*)f default_axeskwargsr- gen_plotsretfigs r_check_plot_worksrs6$% % Cjj3779-  Q.v. 7C  1 1# 6 7 # J #s ABBc+ K|di|yw)z' Create plot in a default way. Nrrrrrs rrr s +f+s c+Kd|vr|jd|di||tjjurd|vsJ|jd|d<|di|yw)z9 Create plot on two subplots forcefully created. rNr) add_subplotpdplottingbootstrap_plotrs rrr'sf 6  +f+BKK & &&6!!!s+t +f+sA!A#)NT)T)rAxes | Sequence[Axes]r@boolreturnNone)NNN)NNNN)linearr)rrrzSequence[Axes])rr)r^)F)(__doc__ __future__rtypingrnumpyrXpandas.core.dtypes.apirpandasrrpandas._testing_testingr(collections.abcrrr rrr4r<rArKrarrwrzrr rrrrrrrrrrrrr s# /($+0'...((".=&@(,G^-$)X  ":?C:%z*,*Z;  -` r