Skip to content

Commit e45a6c1

Browse files
COMPAT: mpl 3.0 (#22870)
* COMPAT: mpl 3.0 * faster test
1 parent d115900 commit e45a6c1

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

doc/source/whatsnew/v0.24.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ Other Enhancements
193193
- :meth:`Series.resample` and :meth:`DataFrame.resample` have gained the :meth:`Resampler.quantile` (:issue:`15023`).
194194
- :meth:`Index.to_frame` now supports overriding column name(s) (:issue:`22580`).
195195
- New attribute :attr:`__git_version__` will return git commit sha of current build (:issue:`21295`).
196+
- Compatibility with Matplotlib 3.0 (:issue:`22790`).
197+
196198
.. _whatsnew_0240.api_breaking:
197199

198200
Backwards incompatible API changes

pandas/plotting/_compat.py

+1
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ def inner():
2929
_mpl_ge_2_0_1 = _mpl_version('2.0.1', operator.ge)
3030
_mpl_ge_2_1_0 = _mpl_version('2.1.0', operator.ge)
3131
_mpl_ge_2_2_0 = _mpl_version('2.2.0', operator.ge)
32+
_mpl_ge_3_0_0 = _mpl_version('3.0.0', operator.ge)

pandas/plotting/_core.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232

3333
from pandas.plotting._compat import (_mpl_ge_1_3_1,
3434
_mpl_ge_1_5_0,
35-
_mpl_ge_2_0_0)
35+
_mpl_ge_2_0_0,
36+
_mpl_ge_3_0_0)
3637
from pandas.plotting._style import (plot_params,
3738
_get_standard_colors)
3839
from pandas.plotting._tools import (_subplots, _flatten, table,
@@ -843,11 +844,16 @@ def _plot_colorbar(self, ax, **kwds):
843844
# For a more detailed description of the issue
844845
# see the following link:
845846
# https://github.com/ipython/ipython/issues/11215
846-
847847
img = ax.collections[0]
848848
cbar = self.fig.colorbar(img, ax=ax, **kwds)
849+
850+
if _mpl_ge_3_0_0():
851+
# The workaround below is no longer necessary.
852+
return
853+
849854
points = ax.get_position().get_points()
850855
cbar_points = cbar.ax.get_position().get_points()
856+
851857
cbar.ax.set_position([cbar_points[0, 0],
852858
points[0, 1],
853859
cbar_points[1, 0] - cbar_points[0, 0],

pandas/tests/plotting/common.py

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def setup_method(self, method):
5757
self.mpl_ge_2_0_0 = plotting._compat._mpl_ge_2_0_0()
5858
self.mpl_ge_2_0_1 = plotting._compat._mpl_ge_2_0_1()
5959
self.mpl_ge_2_2_0 = plotting._compat._mpl_ge_2_2_0()
60+
self.mpl_ge_3_0_0 = plotting._compat._mpl_ge_3_0_0()
6061

6162
if self.mpl_ge_1_4_0:
6263
self.bp_n_objects = 7

pandas/tests/plotting/test_datetimelike.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def test_high_freq(self):
151151
freaks = ['ms', 'us']
152152
for freq in freaks:
153153
_, ax = self.plt.subplots()
154-
rng = date_range('1/1/2012', periods=100000, freq=freq)
154+
rng = date_range('1/1/2012', periods=100, freq=freq)
155155
ser = Series(np.random.randn(len(rng)), rng)
156156
_check_plot_works(ser.plot, ax=ax)
157157

@@ -1492,7 +1492,11 @@ def test_matplotlib_scatter_datetime64(self):
14921492
ax.scatter(x="time", y="y", data=df)
14931493
fig.canvas.draw()
14941494
label = ax.get_xticklabels()[0]
1495-
assert label.get_text() == '2017-12-12'
1495+
if self.mpl_ge_3_0_0:
1496+
expected = "2017-12-08"
1497+
else:
1498+
expected = "2017-12-12"
1499+
assert label.get_text() == expected
14961500

14971501

14981502
def _check_plot_works(f, freq=None, series=None, *args, **kwargs):

0 commit comments

Comments
 (0)