'VfiAdZddlmZddlmZddlZddlmZddl Z ddl m Z ddl m Zer ddlmZddlmZd)d Zd)d Zd Zd*d Zd*d+dZdZd,dZdZd-dZd.dZd,dZd/dZd0dZ d)dZ ifd Z!d1d"Z"d#Z#d$Z$d2d&Z%d'Z&d(Z'dS)3zF Module consolidating common testing functions for checking plotting. ) annotations) TYPE_CHECKINGN) is_list_like)Series)SequenceAxesTc|r|tdt|}|D]e}|rK|Jt||O|JfdS)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 Kc:\PYTHON\DbComparer\venv\Lib\site-packages\pandas/tests/plotting/common.py_check_legend_labelsrsJFNHIII D ! !D++  +==??... r}}88::F C C C C==??**** ++c|r|td|r-|\}}d|D}||ksJdS|JdS)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 Truec6g|]}|S) get_marker).0handles r z(_check_legend_marker..@s$===66$$&&===r)r get_legend_handles_labelsr )rexpected_markersrhandles_markerss r_check_legend_markerr#/sK$,IJJJ'1133 ==W===*******}}&&&&&rcvddlm}|}|}t|t|ksJt ||D]B\}}|}|}t j||C|ddS)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_datar8Fs$#####||~~H||~~H x==CMM ) ) ) )(++//S!!!! vv....IIercddlm}t||st|s|g}|D]}||ksJdS)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) collectionsrr:patchs r_check_visibler@]sw211111 k: . .$|K7P7P$"m ..  ""g-----..rrAxes | Sequence[Axes]filledboolreturnNonec\t|}|D]}|jD]}|j|ksJdS)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)rrBrr?s r_check_patches_all_filledrIqsV D ! !D((Z ( (E:''''' (((rc|}tt||fd|jDS)Nc g|] }| Srr)rvmappeds rrz&_get_colors_mapped..s - - -!F1I - - -r)uniquedictr*values)seriescolorsrNrMs @r_get_colors_mappedrSsE ]]__F#ff%% & &F - - - -v} - - --rc&ddlm}ddlm}m}m}ddlm}|j} ||'t||}|dt|}t|t|ksJt||D]\} } t| |r*| } | | } nNt| ||fr(t| d} n| } | | } | | ksJ||'t||}|dt|}t|t|ksJt||D]\} } t| |r| d} n| } t| t$jrt| } | | } | | ksJdSdS)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:LineCollectionPolyCollection)Line2DN) matplotlibrRr;r:rUrVmatplotlib.linesrWColorConverterrSr)r*r< get_colorto_rgbatuple get_edgecolor get_facecolornpndarray)r> linecolors facecolorsmappingrRr:rUrVrWconvr?colorresultexpecteds r _check_colorsrist "!!!!! ('''''  D  +GZ@@J#$6c+&6&6$67J;3z??2222 Z88 & &LE5%(( /**f--ENN#CDD /u2244Q788,,..||E**HX%%%%%  +GZ@@J#$6c+&6&6$67J;3z??2222 Z88 & &LE5%,, /,,..q1,,..&"*-- 'v||E**HX%%%%%# & &rct|s||ksJdSd|D}t|t|ksJt||D] \}}||ksJdS)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 c6g|]}|Sr)get_text)rts rrz&_check_text_labels..s ...1!**,,...rN)rrlr)r*)textsrhrlabeles rrrs   ~~8++++++.....6{{c(mm++++FH--  HE1A:::::  rcFddlm}t|}|D]}||t|j|r|}n+||dz}|D]T}|'tj| ||'tj| |U||t|j |r| }n+| | dz}|D]T}|'tj| ||'tj| |UdS)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.tickerrrr r<xaxisget_minor_formatterget_xticklabelsr,r- get_fontsize get_rotationyaxisget_yticklabels) r xlabelsizexrot ylabelsizeyrotrrrrros r_check_ticks_propsrs 0///// D ! !DGG  !T%5"(6688-HH O++--++--0B0B0B0N0NN G G)*5+=+=+?+?LLL#*5+=+=+?+?FFF  !T%5"(6688-HH O++--++--0B0B0B0N0NN G G)*5+=+=+?+?LLL#*5+=+=+?+?FFF3GGrlinearct|}|D]@}|j|ksJ|j|ksJAdS)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)rrurzrs r_check_ax_scalesr sk D ! !D--x!!##u,,,,x!!##u,,,,,--rcddlm}|d}t|}|At||ksJ|D])}t|dksJ*|t }t }||D]j}|} || dd|| ddkt|t|f} | |ksJtj |dj tj|tjdS)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.toolsrr r) get_childrenset get_position get_pointsaddr,assert_numpy_array_equalfigureget_size_inchesr`arrayfloat64) raxes_numlayoutfigsizer visible_axesrx_sety_setpointsrgs r_check_axes_shaperst?>>>>>#D))L<  H,,,, . .Br(())A----- ,t$$ $ $B__&&1133F IIfQil # # # IIfQil # # # #e**c%jj)Q..00  +++rSequence[Axes]c@ddlm}||}d|D}|S)z Flatten axes, and filter only visible Parameters ---------- axes : matplotlib Axes object, or its list-like rrc:g|]}||Sr)r=)rrs rrz$_flatten_visible..Ws' : : :2)9)9 :B : : :r)rr)rr axes_ndarrays rr r Ks=?>>>>><%%L : : : : :D Krct|}|D]R}|j}d}d}|D]2}t|dd}t|dd} |r|dz }| r|dz }3||ksJ||ksJSdS)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_yerrrN)r containersgetattr) rxerryerrrr xerr_count yerr_countcrrs r_check_has_errorbarsr[s D ! !D " "]     Aq*e44Hq*e44H a  a z!!!!z!!!!! " "rcddlm}t|td}|Y|d}t |||sJ|dkr3t |j|sJt |jtsJdSdS|&t|D]}t ||sJdSt |tsJt| t|ksJ| D]\}}t |||sJ|dkr|r| |ksJ@|dkrU|r|j |ksJt |j|sJt |jtsJ|dkr2|dd} | j } |r| |ksJtdS) 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)rOrbothNrOrrmedians)matplotlib.axesr rOr]r<rlinesr rsortedkeysitems get_titlerAssertionError) returned return_type expected_keyscheck_ax_titler typesrkeyvalueliners r_check_box_return_typerws7&%$$$$$4 7 7E   K(E+$677777 & hk400 0 00hnd33 3 33 ! 3 3  %h// + +!!T****** F(F+++++hmmoo&&&*?*?????"..** % %JCeU;%788 8 88f$$!4 ??,,3333&&!7 8--//36666!%(D11111!%+t444444&&Y'*y!3>>++s2222$$# % %rcddlfd}d}|D]}jddt|z||dz }dd|jd d|i||rJjjddt|z||dz }dd |jd |dd ||rJj|d vrjddt|z||dz }dd |jd d|i||sJjjddt|z||dz }dd|jd |d d ||sJjdS) Nrc2jj}jj}t d|D}t d|D}|o| S)Nc3JK|]}|j VdSNgridliner=rgs r z;_check_grid_settings..is_grid_on..3@@Aqz--///@@@@@@rc3JK|]}|j VdSrrrs rrz;_check_grid_settings..is_grid_on..rr)r'gcaruget_major_ticksrzr%)xticksyticksxoffyoffmpls r is_grid_onz(_check_grid_settings..is_grid_ons!!'7799!!'7799@@@@@@@@@@@@@@MT""rrrF)gridkindT)rr)piehexbinscatterr)rXr'subplotr)rcplotclf)objkindskwsrspndxrrs @r_check_grid_settingsrsi##### E 1a#e**ne444   vE"""""d"c""":<<  1a#e**ne444   vD!!!.d..#...:<<  3 3 3 J  q!c%jj.% 8 8 8 QJE FF6F % % % CH & &$ &# & & &:<<  < JNN    J  q!c%jj.% 8 8 8 QJE FF6F & & & CH 1$T 1 1S 1 1 1:<<  < JNN   9rrfc,fd|dDS)zL Auxiliary function for correctly unpacking cycler after MPL >= 1.5 c g|] }| Srr)rrLfields rrz"_unpack_cycler..s : : :AeH : : :rzaxes.prop_cycler)rcParamsrs `r_unpack_cyclerrs% ; : : :h'89 : : ::rc|jdS)Nx _shared_axesrs r get_x_axisr ?3 rc|jdS)Nyrrs r get_y_axisrrrFc Vddlm}|rt}nt}d} |d|}||||fi|D]}tj| | |n#| |wxYw|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. rNr) r&r'_gen_default_plot_gen_two_subplotsgetgcfrr,"assert_is_valid_plot_return_objectr.)f default_axeskwargsr1 gen_plotsretfigs r_check_plot_worksrs6$#####&% % Cjj37799--  9Q..v.. 7 7C  1# 6 6 6 6 7 # # Js ABB&c+K|di|VdS)z' Create plot in a default way. Nrrrrrs rrr s& !++f++rc+Kd|vr|d|di|V|tjjurd|vsJn|d|d<|di|VdS)z9 Create plot on two subplots forcefully created. rNr) add_subplotpdplottingbootstrap_plotrs rrr's 6  !++f++BK &&&6!!!!!s++t !++f++r)NT)T)rrArBrCrDrE)NNN)NNNN)rr)rrArDr)rr)rf)F)(__doc__ __future__rtypingrnumpyr`pandas.core.dtypes.apirpandasrrpandas._testing_testingr,collections.abcrrr rr#r8r@rIrSrirrrrr rrrrrrrrrrrrrsT#""""" //////%(((((($$$$$$++++0''''......(((((("...=&=&=&=&@(,G,G,G,G^----$))))X     """":?C:%:%:%:%z*,****Z;;;;      ----`     r