47
47
from pandas .io .formats .printing import pprint_thing
48
48
49
49
mpl = pytest .importorskip ("matplotlib" )
50
+ plt = pytest .importorskip ("matplotlib.pyplot" )
50
51
51
52
52
53
class TestDataFramePlots :
@@ -323,8 +324,6 @@ def test_xcompat(self):
323
324
assert not isinstance (lines [0 ].get_xdata (), PeriodIndex )
324
325
_check_ticks_props (ax , xrot = 30 )
325
326
326
- tm .close ()
327
-
328
327
def test_xcompat_plot_params (self ):
329
328
df = tm .makeTimeDataFrame ()
330
329
plotting .plot_params ["xaxis.compat" ] = True
@@ -333,8 +332,6 @@ def test_xcompat_plot_params(self):
333
332
assert not isinstance (lines [0 ].get_xdata (), PeriodIndex )
334
333
_check_ticks_props (ax , xrot = 30 )
335
334
336
- tm .close ()
337
-
338
335
def test_xcompat_plot_params_x_compat (self ):
339
336
df = tm .makeTimeDataFrame ()
340
337
plotting .plot_params ["x_compat" ] = False
@@ -344,8 +341,6 @@ def test_xcompat_plot_params_x_compat(self):
344
341
assert not isinstance (lines [0 ].get_xdata (), PeriodIndex )
345
342
assert isinstance (PeriodIndex (lines [0 ].get_xdata ()), PeriodIndex )
346
343
347
- tm .close ()
348
-
349
344
def test_xcompat_plot_params_context_manager (self ):
350
345
df = tm .makeTimeDataFrame ()
351
346
# useful if you're plotting a bunch together
@@ -355,8 +350,6 @@ def test_xcompat_plot_params_context_manager(self):
355
350
assert not isinstance (lines [0 ].get_xdata (), PeriodIndex )
356
351
_check_ticks_props (ax , xrot = 30 )
357
352
358
- tm .close ()
359
-
360
353
def test_xcompat_plot_period (self ):
361
354
df = tm .makeTimeDataFrame ()
362
355
ax = df .plot ()
@@ -376,7 +369,6 @@ def test_period_compat(self):
376
369
377
370
df .plot ()
378
371
mpl .pyplot .axhline (y = 0 )
379
- tm .close ()
380
372
381
373
@pytest .mark .parametrize ("index_dtype" , [np .int64 , np .float64 ])
382
374
def test_unsorted_index (self , index_dtype ):
@@ -390,7 +382,6 @@ def test_unsorted_index(self, index_dtype):
390
382
rs = lines .get_xydata ()
391
383
rs = Series (rs [:, 1 ], rs [:, 0 ], dtype = np .int64 , name = "y" )
392
384
tm .assert_series_equal (rs , df .y , check_index_type = False )
393
- tm .close ()
394
385
395
386
@pytest .mark .parametrize (
396
387
"df" ,
@@ -956,14 +947,12 @@ def test_boxplot(self, hist_df):
956
947
ax .xaxis .get_ticklocs (), np .arange (1 , len (numeric_cols ) + 1 )
957
948
)
958
949
assert len (ax .lines ) == 7 * len (numeric_cols )
959
- tm .close ()
960
950
961
951
def test_boxplot_series (self , hist_df ):
962
952
df = hist_df
963
953
series = df ["height" ]
964
954
axes = series .plot .box (rot = 40 )
965
955
_check_ticks_props (axes , xrot = 40 , yrot = 0 )
966
- tm .close ()
967
956
968
957
_check_plot_works (series .plot .box )
969
958
@@ -1093,7 +1082,6 @@ def test_hist_df_series(self):
1093
1082
series = Series (np .random .rand (10 ))
1094
1083
axes = series .plot .hist (rot = 40 )
1095
1084
_check_ticks_props (axes , xrot = 40 , yrot = 0 )
1096
- tm .close ()
1097
1085
1098
1086
def test_hist_df_series_cumulative_density (self ):
1099
1087
from matplotlib .patches import Rectangle
@@ -1103,7 +1091,6 @@ def test_hist_df_series_cumulative_density(self):
1103
1091
# height of last bin (index 5) must be 1.0
1104
1092
rects = [x for x in ax .get_children () if isinstance (x , Rectangle )]
1105
1093
tm .assert_almost_equal (rects [- 1 ].get_height (), 1.0 )
1106
- tm .close ()
1107
1094
1108
1095
def test_hist_df_series_cumulative (self ):
1109
1096
from matplotlib .patches import Rectangle
@@ -1113,7 +1100,6 @@ def test_hist_df_series_cumulative(self):
1113
1100
rects = [x for x in ax .get_children () if isinstance (x , Rectangle )]
1114
1101
1115
1102
tm .assert_almost_equal (rects [- 2 ].get_height (), 10.0 )
1116
- tm .close ()
1117
1103
1118
1104
def test_hist_df_orientation (self ):
1119
1105
df = DataFrame (np .random .randn (10 , 4 ))
@@ -1801,8 +1787,6 @@ def test_errorbar_asymmetrical(self):
1801
1787
with pytest .raises (ValueError , match = msg ):
1802
1788
df .plot (yerr = err .T )
1803
1789
1804
- tm .close ()
1805
-
1806
1790
def test_table (self ):
1807
1791
df = DataFrame (np .random .rand (10 , 3 ), index = list (string .ascii_letters [:10 ]))
1808
1792
_check_plot_works (df .plot , table = True )
@@ -1897,13 +1881,12 @@ def _check(axes):
1897
1881
df .plot (x = "a" , y = "b" , title = "title" , ax = ax , sharex = True )
1898
1882
gs .tight_layout (plt .gcf ())
1899
1883
_check (axes )
1900
- tm .close ()
1884
+ plt .close ("all" )
1901
1885
1902
1886
gs , axes = _generate_4_axes_via_gridspec ()
1903
1887
with tm .assert_produces_warning (UserWarning ):
1904
1888
axes = df .plot (subplots = True , ax = axes , sharex = True )
1905
1889
_check (axes )
1906
- tm .close ()
1907
1890
1908
1891
def test_sharex_false_and_ax (self ):
1909
1892
# https://github.com/pandas-dev/pandas/issues/9737 using gridspec,
@@ -1930,7 +1913,6 @@ def test_sharex_false_and_ax(self):
1930
1913
_check_visible (ax .get_yticklabels (), visible = True )
1931
1914
_check_visible (ax .get_xticklabels (), visible = True )
1932
1915
_check_visible (ax .get_xticklabels (minor = True ), visible = True )
1933
- tm .close ()
1934
1916
1935
1917
def test_sharey_and_ax (self ):
1936
1918
# https://github.com/pandas-dev/pandas/issues/9737 using gridspec,
@@ -1963,15 +1945,14 @@ def _check(axes):
1963
1945
df .plot (x = "a" , y = "b" , title = "title" , ax = ax , sharey = True )
1964
1946
gs .tight_layout (plt .gcf ())
1965
1947
_check (axes )
1966
- tm .close ()
1948
+ plt .close ("all" )
1967
1949
1968
1950
gs , axes = _generate_4_axes_via_gridspec ()
1969
1951
with tm .assert_produces_warning (UserWarning ):
1970
1952
axes = df .plot (subplots = True , ax = axes , sharey = True )
1971
1953
1972
1954
gs .tight_layout (plt .gcf ())
1973
1955
_check (axes )
1974
- tm .close ()
1975
1956
1976
1957
def test_sharey_and_ax_tight (self ):
1977
1958
# https://github.com/pandas-dev/pandas/issues/9737 using gridspec,
@@ -2021,7 +2002,7 @@ def test_memory_leak(self, kind):
2021
2002
ref = weakref .ref (df .plot (kind = kind , ** args ))
2022
2003
2023
2004
# have matplotlib delete all the figures
2024
- tm .close ()
2005
+ plt .close ("all" )
2025
2006
# force a garbage collection
2026
2007
gc .collect ()
2027
2008
assert ref () is None
0 commit comments