From b59fd148979ab7c2c1b7a233c9351fbe33ea5318 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Fri, 28 Sep 2018 08:03:08 -0500 Subject: [PATCH 1/2] COMPAT: mpl 3.0 --- doc/source/whatsnew/v0.24.0.txt | 2 ++ pandas/plotting/_compat.py | 1 + pandas/plotting/_core.py | 10 ++++++++-- pandas/tests/plotting/common.py | 1 + pandas/tests/plotting/test_datetimelike.py | 6 +++++- 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index 481c31d2410a9..3e1711edb0f27 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -193,6 +193,8 @@ Other Enhancements - :meth:`Series.resample` and :meth:`DataFrame.resample` have gained the :meth:`Resampler.quantile` (:issue:`15023`). - :meth:`Index.to_frame` now supports overriding column name(s) (:issue:`22580`). - New attribute :attr:`__git_version__` will return git commit sha of current build (:issue:`21295`). +- Compatibility with Matplotlib 3.0 (:issue:`22790`). + .. _whatsnew_0240.api_breaking: Backwards incompatible API changes diff --git a/pandas/plotting/_compat.py b/pandas/plotting/_compat.py index 46ebd4217862d..5032b259e9831 100644 --- a/pandas/plotting/_compat.py +++ b/pandas/plotting/_compat.py @@ -29,3 +29,4 @@ def inner(): _mpl_ge_2_0_1 = _mpl_version('2.0.1', operator.ge) _mpl_ge_2_1_0 = _mpl_version('2.1.0', operator.ge) _mpl_ge_2_2_0 = _mpl_version('2.2.0', operator.ge) +_mpl_ge_3_0_0 = _mpl_version('3.0.0', operator.ge) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 4fa3b51c60ee4..77c97412bd3d7 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -32,7 +32,8 @@ from pandas.plotting._compat import (_mpl_ge_1_3_1, _mpl_ge_1_5_0, - _mpl_ge_2_0_0) + _mpl_ge_2_0_0, + _mpl_ge_3_0_0) from pandas.plotting._style import (plot_params, _get_standard_colors) from pandas.plotting._tools import (_subplots, _flatten, table, @@ -843,11 +844,16 @@ def _plot_colorbar(self, ax, **kwds): # For a more detailed description of the issue # see the following link: # https://github.com/ipython/ipython/issues/11215 - img = ax.collections[0] cbar = self.fig.colorbar(img, ax=ax, **kwds) + + if _mpl_ge_3_0_0(): + # The workaround below is no longer necessary. + return + points = ax.get_position().get_points() cbar_points = cbar.ax.get_position().get_points() + cbar.ax.set_position([cbar_points[0, 0], points[0, 1], cbar_points[1, 0] - cbar_points[0, 0], diff --git a/pandas/tests/plotting/common.py b/pandas/tests/plotting/common.py index 09687dd97bd43..5c88926828fa6 100644 --- a/pandas/tests/plotting/common.py +++ b/pandas/tests/plotting/common.py @@ -57,6 +57,7 @@ def setup_method(self, method): self.mpl_ge_2_0_0 = plotting._compat._mpl_ge_2_0_0() self.mpl_ge_2_0_1 = plotting._compat._mpl_ge_2_0_1() self.mpl_ge_2_2_0 = plotting._compat._mpl_ge_2_2_0() + self.mpl_ge_3_0_0 = plotting._compat._mpl_ge_3_0_0() if self.mpl_ge_1_4_0: self.bp_n_objects = 7 diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index 0abe82d138e5e..387c83e4d00a0 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -1492,7 +1492,11 @@ def test_matplotlib_scatter_datetime64(self): ax.scatter(x="time", y="y", data=df) fig.canvas.draw() label = ax.get_xticklabels()[0] - assert label.get_text() == '2017-12-12' + if self.mpl_ge_3_0_0: + expected = "2017-12-08" + else: + expected = "2017-12-12" + assert label.get_text() == expected def _check_plot_works(f, freq=None, series=None, *args, **kwargs): From 2ca4963f4c29e3f7e9168d7d5a65e2b8ea7d75da Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Fri, 28 Sep 2018 08:13:18 -0500 Subject: [PATCH 2/2] faster test --- pandas/tests/plotting/test_datetimelike.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index 387c83e4d00a0..de6f6b931987c 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -151,7 +151,7 @@ def test_high_freq(self): freaks = ['ms', 'us'] for freq in freaks: _, ax = self.plt.subplots() - rng = date_range('1/1/2012', periods=100000, freq=freq) + rng = date_range('1/1/2012', periods=100, freq=freq) ser = Series(np.random.randn(len(rng)), rng) _check_plot_works(ser.plot, ax=ax)