7
7
8
8
from __future__ import annotations
9
9
10
- import os
11
10
from typing import (
12
11
TYPE_CHECKING ,
13
12
Sequence ,
22
21
from pandas .core .dtypes .api import is_list_like
23
22
24
23
import pandas as pd
25
- from pandas import (
26
- DataFrame ,
27
- Series ,
28
- to_datetime ,
29
- )
24
+ from pandas import Series
30
25
import pandas ._testing as tm
31
26
32
27
if TYPE_CHECKING :
@@ -39,62 +34,12 @@ class TestPlotBase:
39
34
This is a common base class used for various plotting tests
40
35
"""
41
36
42
- def setup_method (self , method ):
43
-
37
+ def setup_method (self ):
44
38
import matplotlib as mpl
45
39
46
- from pandas .plotting ._matplotlib import compat
47
-
48
- self .compat = compat
49
-
50
40
mpl .rcdefaults ()
51
41
52
- self .start_date_to_int64 = 812419200000000000
53
- self .end_date_to_int64 = 819331200000000000
54
-
55
- self .mpl_ge_2_2_3 = compat .mpl_ge_2_2_3 ()
56
- self .mpl_ge_3_0_0 = compat .mpl_ge_3_0_0 ()
57
- self .mpl_ge_3_1_0 = compat .mpl_ge_3_1_0 ()
58
- self .mpl_ge_3_2_0 = compat .mpl_ge_3_2_0 ()
59
-
60
- self .bp_n_objects = 7
61
- self .polycollection_factor = 2
62
- self .default_figsize = (6.4 , 4.8 )
63
- self .default_tick_position = "left"
64
-
65
- n = 100
66
- with tm .RNGContext (42 ):
67
- gender = np .random .choice (["Male" , "Female" ], size = n )
68
- classroom = np .random .choice (["A" , "B" , "C" ], size = n )
69
-
70
- self .hist_df = DataFrame (
71
- {
72
- "gender" : gender ,
73
- "classroom" : classroom ,
74
- "height" : np .random .normal (66 , 4 , size = n ),
75
- "weight" : np .random .normal (161 , 32 , size = n ),
76
- "category" : np .random .randint (4 , size = n ),
77
- "datetime" : to_datetime (
78
- np .random .randint (
79
- self .start_date_to_int64 ,
80
- self .end_date_to_int64 ,
81
- size = n ,
82
- dtype = np .int64 ,
83
- )
84
- ),
85
- }
86
- )
87
-
88
- self .tdf = tm .makeTimeDataFrame ()
89
- self .hexbin_df = DataFrame (
90
- {
91
- "A" : np .random .uniform (size = 20 ),
92
- "B" : np .random .uniform (size = 20 ),
93
- "C" : np .arange (20 ) + np .random .uniform (size = 20 ),
94
- }
95
- )
96
-
97
- def teardown_method (self , method ):
42
+ def teardown_method (self ):
98
43
tm .close ()
99
44
100
45
@cache_readonly
@@ -166,13 +111,12 @@ def _check_data(self, xp, rs):
166
111
xp_lines = xp .get_lines ()
167
112
rs_lines = rs .get_lines ()
168
113
169
- def check_line (xpl , rsl ):
114
+ assert len (xp_lines ) == len (rs_lines )
115
+ for xpl , rsl in zip (xp_lines , rs_lines ):
170
116
xpdata = xpl .get_xydata ()
171
117
rsdata = rsl .get_xydata ()
172
118
tm .assert_almost_equal (xpdata , rsdata )
173
119
174
- assert len (xp_lines ) == len (rs_lines )
175
- [check_line (xpl , rsl ) for xpl , rsl in zip (xp_lines , rs_lines )]
176
120
tm .close ()
177
121
178
122
def _check_visible (self , collections , visible = True ):
@@ -387,7 +331,7 @@ def _check_axes_shape(self, axes, axes_num=None, layout=None, figsize=None):
387
331
from pandas .plotting ._matplotlib .tools import flatten_axes
388
332
389
333
if figsize is None :
390
- figsize = self . default_figsize
334
+ figsize = ( 6.4 , 4.8 )
391
335
visible_axes = self ._flatten_visible (axes )
392
336
393
337
if axes_num is not None :
@@ -525,15 +469,8 @@ def _check_grid_settings(self, obj, kinds, kws={}):
525
469
def is_grid_on ():
526
470
xticks = self .plt .gca ().xaxis .get_major_ticks ()
527
471
yticks = self .plt .gca ().yaxis .get_major_ticks ()
528
- # for mpl 2.2.2, gridOn and gridline.get_visible disagree.
529
- # for new MPL, they are the same.
530
-
531
- if self .mpl_ge_3_1_0 :
532
- xoff = all (not g .gridline .get_visible () for g in xticks )
533
- yoff = all (not g .gridline .get_visible () for g in yticks )
534
- else :
535
- xoff = all (not g .gridOn for g in xticks )
536
- yoff = all (not g .gridOn for g in yticks )
472
+ xoff = all (not g .gridline .get_visible () for g in xticks )
473
+ yoff = all (not g .gridline .get_visible () for g in yticks )
537
474
538
475
return not (xoff and yoff )
539
476
@@ -572,10 +509,18 @@ def _unpack_cycler(self, rcParams, field="color"):
572
509
return [v [field ] for v in rcParams ["axes.prop_cycle" ]]
573
510
574
511
def get_x_axis (self , ax ):
575
- return ax ._shared_axes ["x" ] if self .compat .mpl_ge_3_5_0 () else ax ._shared_x_axes
512
+ from pandas .plotting ._matplotlib .compat import mpl_ge_3_5_0
513
+
514
+ if mpl_ge_3_5_0 ():
515
+ return ax ._shared_axes ["x" ]
516
+ return ax ._shared_x_axes
576
517
577
518
def get_y_axis (self , ax ):
578
- return ax ._shared_axes ["y" ] if self .compat .mpl_ge_3_5_0 () else ax ._shared_y_axes
519
+ from pandas .plotting ._matplotlib .compat import mpl_ge_3_5_0
520
+
521
+ if mpl_ge_3_5_0 ():
522
+ return ax ._shared_axes ["y" ]
523
+ return ax ._shared_y_axes
579
524
580
525
581
526
def _check_plot_works (f , filterwarnings = "always" , default_axes = False , ** kwargs ):
@@ -656,8 +601,3 @@ def _gen_two_subplots(f, fig, **kwargs):
656
601
else :
657
602
kwargs ["ax" ] = fig .add_subplot (212 )
658
603
yield f (** kwargs )
659
-
660
-
661
- def curpath ():
662
- pth , _ = os .path .split (os .path .abspath (__file__ ))
663
- return pth
0 commit comments