diff --git a/pandas/tests/plotting/common.py b/pandas/tests/plotting/common.py index e51dd06881c4f..fd5a66049bd24 100644 --- a/pandas/tests/plotting/common.py +++ b/pandas/tests/plotting/common.py @@ -535,9 +535,6 @@ def _check_plot_works(f, default_axes=False, **kwargs): for ret in gen_plots(f, fig, **kwargs): tm.assert_is_valid_plot_return_object(ret) - with tm.ensure_clean(return_filelike=True) as path: - plt.savefig(path) - finally: plt.close(fig) diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index 42f1a30983414..28bd5fe4c4e5e 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -1645,9 +1645,6 @@ def _check_plot_works(f, freq=None, series=None, *args, **kwargs): ret = f(*args, **kwargs) assert ret is not None # TODO: do something more intelligent - with tm.ensure_clean(return_filelike=True) as path: - plt.savefig(path) - # GH18439, GH#24088, statsmodels#4772 with tm.ensure_clean(return_filelike=True) as path: pickle.dump(fig, path) diff --git a/pandas/tests/plotting/test_misc.py b/pandas/tests/plotting/test_misc.py index f0d3d66eff462..5b06cd1ab296a 100644 --- a/pandas/tests/plotting/test_misc.py +++ b/pandas/tests/plotting/test_misc.py @@ -1,4 +1,5 @@ """ Test cases for misc plot functions """ +import os import numpy as np import pytest @@ -10,7 +11,9 @@ Index, Series, Timestamp, + date_range, interval_range, + period_range, plotting, ) import pandas._testing as tm @@ -23,6 +26,7 @@ ) mpl = pytest.importorskip("matplotlib") +plt = pytest.importorskip("matplotlib.pyplot") cm = pytest.importorskip("matplotlib.cm") @@ -69,6 +73,30 @@ def test_get_accessor_args(): assert len(kwargs) == 24 +@pytest.mark.parametrize("kind", plotting.PlotAccessor._all_kinds) +@pytest.mark.parametrize( + "data", [DataFrame(np.arange(15).reshape(5, 3)), Series(range(5))] +) +@pytest.mark.parametrize( + "index", + [ + Index(range(5)), + date_range("2020-01-01", periods=5), + period_range("2020-01-01", periods=5), + ], +) +def test_savefig(kind, data, index): + fig, ax = plt.subplots() + data.index = index + kwargs = {} + if kind in ["hexbin", "scatter", "pie"]: + if isinstance(data, Series): + pytest.skip(f"{kind} not supported with Series") + kwargs = {"x": 0, "y": 1} + data.plot(kind=kind, ax=ax, **kwargs) + fig.savefig(os.devnull) + + class TestSeriesPlots: def test_autocorrelation_plot(self): from pandas.plotting import autocorrelation_plot