Skip to content

Commit

Permalink
COMPAT: mpl 3.0 (pandas-dev#22870)
Browse files Browse the repository at this point in the history
* COMPAT: mpl 3.0

* faster test
  • Loading branch information
TomAugspurger authored and victor committed Sep 30, 2018
1 parent 4d66656 commit 7803679
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pandas/plotting/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
10 changes: 8 additions & 2 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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],
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/plotting/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions pandas/tests/plotting/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 7803679

Please sign in to comment.