zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
U
­ý°dMã@s´dZddlmZddlmZmZddlZddlm    Z    ddl
m m Z ddlmZddlZddlmZddlmZer‚ddlmZe jGd    d
„d
ƒƒZdd d „Zdd„Zdd„ZdS)zF
Module consolidating common testing functions for checking plotting.
é)Ú annotations)Ú TYPE_CHECKINGÚSequenceN)Úcache_readonly)Ú is_list_like)ÚSeries©ÚAxesc@sôeZdZdZdd„Zdd„Zedd„ƒZedd    „ƒZd9d d „Z    d:dd„Z
dd„Z d;dd„Z d<ddddœdd„Z dd„Zd=dd„Zdd„Zd>d d!„Zd?d#d$„Zd@d%d&„Zd'd(„Zd)d*„ZdAd,d-„ZdBd.d/„Zifd0d1„ZdCd3d4„Zd5d6„Zd7d8„Zd
S)DÚ TestPlotBasezE
    This is a common base class used for various plotting tests
    cCsddl}| ¡dS©Nr)Ú
matplotlibZ
rcdefaults)ÚselfÚmpl©rúSd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/tests/plotting/common.pyÚ setup_method!szTestPlotBase.setup_methodcCs t ¡dS©N)ÚtmÚclose©r rrrÚteardown_method&szTestPlotBase.teardown_methodcCsddlm}|Sr )Úmatplotlib.pyplotÚpyplot)r Úpltrrrr)s zTestPlotBase.pltcCsddlm}|jS)Nr)Úcolors)r rZcolorConverter)r rrrrÚcolorconverter/s zTestPlotBase.colorconverterNTcCsf|r|dkrtdƒ‚| |¡}|D]>}|rP| ¡dk    s:t‚| | ¡ ¡|¡q"| ¡dks"t‚q"dS)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ÚAssertionErrorÚ_check_text_labelsZ    get_texts)r ÚaxesÚlabelsÚvisibleÚaxrrrÚ_check_legend_labels5s 
z!TestPlotBase._check_legend_labelscCsT|r|dkrtdƒ‚|r@| ¡\}}dd„|Dƒ}||ksPt‚n| ¡dksPt‚dS)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 TruecSsg|] }| ¡‘qSr)Z
get_marker)Ú.0ÚhandlerrrÚ
<listcomp>]sz5TestPlotBase._check_legend_marker.<locals>.<listcomp>)rZget_legend_handles_labelsrr)r r$Zexpected_markersr#ZhandlesÚ_ÚmarkersrrrÚ_check_legend_markerLs  z!TestPlotBase._check_legend_markerc    Cs`| ¡}| ¡}t|ƒt|ƒks$t‚t||ƒD]$\}}| ¡}| ¡}t ||¡q.t ¡dS)z¤
        Check each axes has identical lines
 
        Parameters
        ----------
        xp : matplotlib Axes object
        rs : matplotlib Axes object
        N)Ú    get_linesÚlenrÚzipZ
get_xydatarÚassert_almost_equalr)    r ZxpÚrsZxp_linesZrs_linesZxplZrslZxpdataZrsdatarrrÚ _check_databs    zTestPlotBase._check_datacCsBddlm}t||ƒs$t|ƒs$|g}|D]}| ¡|ks(t‚q(dS)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.collectionsr2Ú
isinstancerÚ get_visibler)r Ú collectionsr#r2ÚpatchrrrÚ_check_visiblevs
zTestPlotBase._check_visiblezAxes | Sequence[Axes]ÚboolÚNone)r!ÚfilledÚreturncCs2| |¡}|D]}|jD]}|j|kst‚qqdS)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)rZpatchesÚfillr)r r!r;r$r7rrrÚ_check_patches_all_filled‰s
 
z&TestPlotBase._check_patches_all_filledcs*| ¡}tt||ƒƒ‰‡fdd„|jDƒS)Ncsg|] }ˆ|‘qSrr©r&Úv©Zmappedrrr( sz3TestPlotBase._get_colors_mapped.<locals>.<listcomp>)ÚuniqueÚdictr.Úvalues)r ZseriesrrBrrArÚ_get_colors_mapped›szTestPlotBase._get_colors_mappedcCs†ddlm}m}m}ddlm}|j}    |dk    rÖ|dk    rR| ||¡}|dt|ƒ…}t|ƒt|ƒksft    ‚t
||ƒD]d\}
} t |
|ƒr–|
  ¡} |      | ¡} n(t |
||fƒr¶t|
 ¡dƒ} n|
 ¡} |      | ¡} | | kspt    ‚qp|dk    r‚|dk    r| ||¡}|dt|ƒ…}t|ƒt|ƒkst    ‚t
||ƒD]Z\}
} t |
|ƒrH|
 ¡d} n|
 ¡} t | tjƒrft| ƒ} |      | ¡} | | ks&t    ‚q&dS)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)r2ÚLineCollectionÚPolyCollection)ÚLine2DN)r3r2rFrGZmatplotlib.linesrHrrEr-rr.r4Z    get_colorZto_rgbaÚtupleZ get_edgecolorZ get_facecolorÚnpZndarray)r r6Z
linecolorsZ
facecolorsÚmappingr2rFrGrHÚconvr7ÚcolorÚresultÚexpectedrrrÚ _check_colors¢s<  
 
 
 
 
zTestPlotBase._check_colorscCs`t|ƒs| ¡|ks\t‚nBdd„|Dƒ}t|ƒt|ƒks<t‚t||ƒD]\}}||ksFt‚qFdS)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
        cSsg|] }| ¡‘qSr)Úget_text)r&Útrrrr(ðsz3TestPlotBase._check_text_labels.<locals>.<listcomp>N)rrQrr-r.)r ZtextsrOr"ÚlabelÚerrrr âs zTestPlotBase._check_text_labelsc
Csddlm}| |¡}|D]ô}|dk    s.|dk    r–t|j ¡|ƒrH| ¡}n| ¡|jdd}|D]4}    |dk    r|t |         ¡|¡|dk    r`t |     
¡|¡q`|dk    s¦|dk    rt|j  ¡|ƒrÀ|  ¡}n|  ¡|j dd}|D]4}    |dk    rôt |         ¡|¡|dk    rØt |     
¡|¡qØqdS)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) Zmatplotlib.tickerrUrr4ÚxaxisZget_minor_formatterZget_xticklabelsrr/Z get_fontsizeZ get_rotationÚyaxisZget_yticklabels)
r r!Z
xlabelsizeZxrotZ
ylabelsizeZyrotrUr$r"rSrrrÚ_check_ticks_propsõs* 
 
 
zTestPlotBase._check_ticks_propsÚlinearcCs<| |¡}|D](}|j ¡|ks$t‚|j ¡|kst‚qdS)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)rrWZ    get_scalerrX)r r!rWrXr$rrrÚ_check_ax_scales%s
zTestPlotBase._check_ax_scalesc    Cs ddlm}|dkrd}| |¡}|dk    rXt|ƒ|ks:t‚|D]}t| ¡ƒdks>t‚q>|dk    rz| ||ƒ¡}||kszt‚t |dj     
¡t j |t j d¡dS)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@)Zdtype)Ú!pandas.plotting._matplotlib.toolsr]rr-rZ get_childrenÚ_get_axes_layoutrZassert_numpy_array_equalÚfigureZget_size_inchesrJÚarrayÚfloat64)    r r!Zaxes_numZlayoutZfigsizer]Z visible_axesr$rNrrrÚ_check_axes_shape6s 
  þzTestPlotBase._check_axes_shapecCsVtƒ}tƒ}|D]4}| ¡ ¡}| |dd¡| |dd¡qt|ƒt|ƒfS)Nré)ÚsetÚ get_positionZ
get_pointsÚaddr-)r r!Zx_setZy_setr$Zpointsrrrr_Zs zTestPlotBase._get_axes_layoutcCs&ddlm}||ƒ}dd„|Dƒ}|S)z—
        Flatten axes, and filter only visible
 
        Parameters
        ----------
        axes : matplotlib Axes object, or its list-like
 
        rr\cSsg|]}| ¡r|‘qSr)r5)r&r$rrrr(psz1TestPlotBase._flatten_visible.<locals>.<listcomp>)r^r])r r!r]rrrrds     zTestPlotBase._flatten_visiblerc Csx| |¡}|D]d}|j}d}d}|D]4}t|ddƒ}    t|ddƒ}
|    rL|d7}|
r$|d7}q$||ksft‚||kst‚qdS)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_yerrrdN)rÚ
containersÚgetattrr) r r!ZxerrZyerrr$rjZ
xerr_countZ
yerr_countÚcrhrirrrÚ_check_has_errorbarsss
 
 z!TestPlotBase._check_has_errorbarsc Cs„ddlm}t|tdœ}|dkrj|dkr,d}t|||ƒs>t‚|dkrft|j|ƒsVt‚t|jtƒsft‚n|dkr”| |¡D]}t||ƒs|t‚q|dSt|t    ƒs¢t‚t
|  ¡ƒt
|ƒksºt‚|  ¡D]¼\}}    t|    ||ƒsÜt‚|dkrú|rø|      ¡|ksøt‚qÂ|dkrD|r|    j  ¡|kst‚t|    j|ƒs0t‚t|    jtƒs~t‚qÂ|dkrz|    dd}
|
j} |r~|   ¡|ks~t‚qÂt‚qÂdS)    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.
        rr)rCr!ÚbothNrCrnr!Zmedians)Úmatplotlib.axesr    rCrIr4rr$ÚlinesrrÚsortedÚkeysÚitemsZ    get_titler!) r ZreturnedÚ return_typeZ expected_keysZcheck_ax_titler    ÚtypesÚrÚkeyÚvalueÚliner!rrrÚ_check_box_return_typeŽs>  
 
 z#TestPlotBase._check_box_return_typecsddl}‡fdd„}d}|D]l}ˆj ddt|ƒ|¡|d7}|jddd|jfd    |i|—Ž|ƒrnt‚ˆj ¡ˆj ddt|ƒ|¡|d7}|jdd
d|jf|dd œ|—Ž|ƒrÆt‚ˆj ¡|d krˆj ddt|ƒ|¡|d7}|jdd
d|jfd    |i|—Ž|ƒs&t‚ˆj ¡ˆj ddt|ƒ|¡|d7}|jddd|jf|d
d œ|—Ž|ƒs€t‚ˆj ¡qdS) NrcsNˆj ¡j ¡}ˆj ¡j ¡}tdd„|Dƒƒ}tdd„|Dƒƒ}|oJ| S)Ncss|]}|j ¡ VqdSr©Zgridliner5©r&ÚgrrrÚ    <genexpr>ÒszHTestPlotBase._check_grid_settings.<locals>.is_grid_on.<locals>.<genexpr>css|]}|j ¡ VqdSrr{r|rrrr~Ós)rZgcarWZget_major_ticksrXÚall)ZxticksZyticksZxoffZyoffrrrÚ
is_grid_onÏs
z5TestPlotBase._check_grid_settings.<locals>.is_grid_onrdér!F)ÚgridÚkindT)rƒr‚)ZpieZhexbinZscatter)r rZsubplotr-ÚrcZplotrÚclf)r ÚobjÚkindsÚkwsrr€ZspndxrƒrrrÚ_check_grid_settingsÊs: 
 
 
 
 
 
 z!TestPlotBase._check_grid_settingsrMcs‡fdd„|dDƒS)zT
        Auxiliary function for correctly unpacking cycler after MPL >= 1.5
        csg|] }|ˆ‘qSrrr?©Úfieldrrr(úsz/TestPlotBase._unpack_cycler.<locals>.<listcomp>zaxes.prop_cycler)r ZrcParamsr‹rrŠrÚ_unpack_cycleröszTestPlotBase._unpack_cyclercCs
|jdS)NÚx©Z _shared_axes©r r$rrrÚ
get_x_axisüszTestPlotBase.get_x_axiscCs
|jdS)NÚyrŽrrrrÚ
get_y_axisÿszTestPlotBase.get_y_axis)NT)NT)T)T)NNN)NNNN)rZrZ)NNN)rr)NT)rM)Ú__name__Ú
__module__Ú __qualname__Ú__doc__rrrrrr%r+r1r8r>rErPr rYr[rcr_rrmrzr‰rŒrr’rrrrr
sH
 
 
 
 
ÿÿ
@ÿ
0
 
$
 
ÿ
< ,
r
Fc    KsŒddlm}|rt}nt}d}z\| d| ¡¡}| ¡|||f|ŽD]}t     |¡qFtj
dd}|  |¡W5QRXW5t |¡X|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`T)Zreturn_filelike) rrÚ_gen_default_plotÚ_gen_two_subplotsrrÚgetZgcfr…Z"assert_is_valid_plot_return_objectZ ensure_cleanZsavefig)ÚfZ default_axesÚkwargsrZ    gen_plotsÚretÚfigÚpathrrrÚ_check_plot_workss   rŸcks|f|ŽVdS)z'
    Create plot in a default way.
    Nr©ršrr›rrrr—6sr—cksVd|kr| d¡|f|ŽV|tjjkr8d|ksFt‚n| d¡|d<|f|ŽVdS)z9
    Create plot on two subplots forcefully created.
    r$éÓéÔN)Z add_subplotÚpdZplottingZbootstrap_plotrr rrrr˜=s
  r˜)F)r–Ú
__future__rÚtypingrrÚnumpyrJZpandas.util._decoratorsrZpandas.util._test_decoratorsÚutilZ_test_decoratorsÚtdZpandas.core.dtypes.apirZpandasr£rZpandas._testingZ_testingrror    Zskip_if_no_mplr
rŸr—r˜rrrrÚ<module>s&      j
3