Skip to content

Commit 8b2477d

Browse files
authored
COMPAT: Matplotlib 3.5.0 (#44523)
* COMPAT: Matplotlib 3.5.0 * try another way * typo * one more typo * Update test_common.py * Update converter.py * fix deprecation warnings?
1 parent 59d031f commit 8b2477d

File tree

9 files changed

+47
-35
lines changed

9 files changed

+47
-35
lines changed

pandas/plotting/_matplotlib/compat.py

+1
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ def inner():
2424
mpl_ge_3_2_0 = _mpl_version("3.2.0", operator.ge)
2525
mpl_ge_3_3_0 = _mpl_version("3.3.0", operator.ge)
2626
mpl_ge_3_4_0 = _mpl_version("3.4.0", operator.ge)
27+
mpl_ge_3_5_0 = _mpl_version("3.5.0", operator.ge)

pandas/plotting/_matplotlib/converter.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ def get_locator(self, dmin, dmax):
357357
locator = MilliSecondLocator(self.tz)
358358
locator.set_axis(self.axis)
359359

360-
locator.set_view_interval(*self.axis.get_view_interval())
361-
locator.set_data_interval(*self.axis.get_data_interval())
360+
locator.axis.set_view_interval(*self.axis.get_view_interval())
361+
locator.axis.set_data_interval(*self.axis.get_data_interval())
362362
return locator
363363

364364
return dates.AutoDateLocator.get_locator(self, dmin, dmax)

pandas/plotting/_matplotlib/core.py

+1
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,7 @@ def _plot_colorbar(self, ax: Axes, **kwds):
10361036
# use the last one which contains the latest information
10371037
# about the ax
10381038
img = ax.collections[-1]
1039+
ax.grid(False)
10391040
cbar = self.fig.colorbar(img, ax=ax, **kwds)
10401041

10411042
if mpl_ge_3_0_0():

pandas/tests/plotting/common.py

+8
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ def setup_method(self, method):
4545

4646
from pandas.plotting._matplotlib import compat
4747

48+
self.compat = compat
49+
4850
mpl.rcdefaults()
4951

5052
self.start_date_to_int64 = 812419200000000000
@@ -569,6 +571,12 @@ def _unpack_cycler(self, rcParams, field="color"):
569571
"""
570572
return [v[field] for v in rcParams["axes.prop_cycle"]]
571573

574+
def get_x_axis(self, ax):
575+
return ax._shared_axes["x"] if self.compat.mpl_ge_3_5_0() else ax._shared_x_axes
576+
577+
def get_y_axis(self, ax):
578+
return ax._shared_axes["y"] if self.compat.mpl_ge_3_5_0() else ax._shared_y_axes
579+
572580

573581
def _check_plot_works(f, filterwarnings="always", default_axes=False, **kwargs):
574582
"""

pandas/tests/plotting/frame/test_frame.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,8 @@ def test_area_sharey_dont_overwrite(self):
525525
df.plot(ax=ax1, kind="area")
526526
df.plot(ax=ax2, kind="area")
527527

528-
assert ax1._shared_y_axes.joined(ax1, ax2)
529-
assert ax2._shared_y_axes.joined(ax1, ax2)
528+
assert self.get_y_axis(ax1).joined(ax1, ax2)
529+
assert self.get_y_axis(ax2).joined(ax1, ax2)
530530

531531
def test_bar_linewidth(self):
532532
df = DataFrame(np.random.randn(5, 5))

pandas/tests/plotting/frame/test_hist_box_by.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -195,33 +195,33 @@ def test_axis_share_x_with_by(self):
195195
ax1, ax2, ax3 = self.hist_df.plot.hist(column="A", by="C", sharex=True)
196196

197197
# share x
198-
assert ax1._shared_x_axes.joined(ax1, ax2)
199-
assert ax2._shared_x_axes.joined(ax1, ax2)
200-
assert ax3._shared_x_axes.joined(ax1, ax3)
201-
assert ax3._shared_x_axes.joined(ax2, ax3)
198+
assert self.get_x_axis(ax1).joined(ax1, ax2)
199+
assert self.get_x_axis(ax2).joined(ax1, ax2)
200+
assert self.get_x_axis(ax3).joined(ax1, ax3)
201+
assert self.get_x_axis(ax3).joined(ax2, ax3)
202202

203203
# don't share y
204-
assert not ax1._shared_y_axes.joined(ax1, ax2)
205-
assert not ax2._shared_y_axes.joined(ax1, ax2)
206-
assert not ax3._shared_y_axes.joined(ax1, ax3)
207-
assert not ax3._shared_y_axes.joined(ax2, ax3)
204+
assert not self.get_y_axis(ax1).joined(ax1, ax2)
205+
assert not self.get_y_axis(ax2).joined(ax1, ax2)
206+
assert not self.get_y_axis(ax3).joined(ax1, ax3)
207+
assert not self.get_y_axis(ax3).joined(ax2, ax3)
208208

209209
@pytest.mark.slow
210210
def test_axis_share_y_with_by(self):
211211
# GH 15079
212212
ax1, ax2, ax3 = self.hist_df.plot.hist(column="A", by="C", sharey=True)
213213

214214
# share y
215-
assert ax1._shared_y_axes.joined(ax1, ax2)
216-
assert ax2._shared_y_axes.joined(ax1, ax2)
217-
assert ax3._shared_y_axes.joined(ax1, ax3)
218-
assert ax3._shared_y_axes.joined(ax2, ax3)
215+
assert self.get_y_axis(ax1).joined(ax1, ax2)
216+
assert self.get_y_axis(ax2).joined(ax1, ax2)
217+
assert self.get_y_axis(ax3).joined(ax1, ax3)
218+
assert self.get_y_axis(ax3).joined(ax2, ax3)
219219

220220
# don't share x
221-
assert not ax1._shared_x_axes.joined(ax1, ax2)
222-
assert not ax2._shared_x_axes.joined(ax1, ax2)
223-
assert not ax3._shared_x_axes.joined(ax1, ax3)
224-
assert not ax3._shared_x_axes.joined(ax2, ax3)
221+
assert not self.get_x_axis(ax1).joined(ax1, ax2)
222+
assert not self.get_x_axis(ax2).joined(ax1, ax2)
223+
assert not self.get_x_axis(ax3).joined(ax1, ax3)
224+
assert not self.get_x_axis(ax3).joined(ax2, ax3)
225225

226226
@pytest.mark.parametrize("figsize", [(12, 8), (20, 10)])
227227
def test_figure_shape_hist_with_by(self, figsize):

pandas/tests/plotting/test_common.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ def test__gen_two_subplots_with_ax(self):
3939
next(gen)
4040
axes = fig.get_axes()
4141
assert len(axes) == 1
42-
assert axes[0].get_geometry() == (2, 1, 2)
42+
subplot_geometry = list(axes[0].get_subplotspec().get_geometry()[:-1])
43+
subplot_geometry[-1] += 1
44+
assert subplot_geometry == [2, 1, 2]

pandas/tests/plotting/test_hist_method.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -728,35 +728,35 @@ def test_axis_share_x(self):
728728
ax1, ax2 = df.hist(column="height", by=df.gender, sharex=True)
729729

730730
# share x
731-
assert ax1._shared_x_axes.joined(ax1, ax2)
732-
assert ax2._shared_x_axes.joined(ax1, ax2)
731+
assert self.get_x_axis(ax1).joined(ax1, ax2)
732+
assert self.get_x_axis(ax2).joined(ax1, ax2)
733733

734734
# don't share y
735-
assert not ax1._shared_y_axes.joined(ax1, ax2)
736-
assert not ax2._shared_y_axes.joined(ax1, ax2)
735+
assert not self.get_y_axis(ax1).joined(ax1, ax2)
736+
assert not self.get_y_axis(ax2).joined(ax1, ax2)
737737

738738
def test_axis_share_y(self):
739739
df = self.hist_df
740740
ax1, ax2 = df.hist(column="height", by=df.gender, sharey=True)
741741

742742
# share y
743-
assert ax1._shared_y_axes.joined(ax1, ax2)
744-
assert ax2._shared_y_axes.joined(ax1, ax2)
743+
assert self.get_y_axis(ax1).joined(ax1, ax2)
744+
assert self.get_y_axis(ax2).joined(ax1, ax2)
745745

746746
# don't share x
747-
assert not ax1._shared_x_axes.joined(ax1, ax2)
748-
assert not ax2._shared_x_axes.joined(ax1, ax2)
747+
assert not self.get_x_axis(ax1).joined(ax1, ax2)
748+
assert not self.get_x_axis(ax2).joined(ax1, ax2)
749749

750750
def test_axis_share_xy(self):
751751
df = self.hist_df
752752
ax1, ax2 = df.hist(column="height", by=df.gender, sharex=True, sharey=True)
753753

754754
# share both x and y
755-
assert ax1._shared_x_axes.joined(ax1, ax2)
756-
assert ax2._shared_x_axes.joined(ax1, ax2)
755+
assert self.get_x_axis(ax1).joined(ax1, ax2)
756+
assert self.get_x_axis(ax2).joined(ax1, ax2)
757757

758-
assert ax1._shared_y_axes.joined(ax1, ax2)
759-
assert ax2._shared_y_axes.joined(ax1, ax2)
758+
assert self.get_y_axis(ax1).joined(ax1, ax2)
759+
assert self.get_y_axis(ax2).joined(ax1, ax2)
760760

761761
@pytest.mark.parametrize(
762762
"histtype, expected",

pandas/tests/plotting/test_series.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ def test_area_sharey_dont_overwrite(self):
154154
abs(self.ts).plot(ax=ax1, kind="area")
155155
abs(self.ts).plot(ax=ax2, kind="area")
156156

157-
assert ax1._shared_y_axes.joined(ax1, ax2)
158-
assert ax2._shared_y_axes.joined(ax1, ax2)
157+
assert self.get_y_axis(ax1).joined(ax1, ax2)
158+
assert self.get_y_axis(ax2).joined(ax1, ax2)
159159

160160
def test_label(self):
161161
s = Series([1, 2])

0 commit comments

Comments
 (0)