Skip to content

Commit 63e3233

Browse files
Backport PR pandas-dev#44523: COMPAT: Matplotlib 3.5.0 (pandas-dev#44555)
Co-authored-by: Thomas Li <[email protected]>
1 parent 4ffccaf commit 63e3233

File tree

8 files changed

+31
-19
lines changed

8 files changed

+31
-19
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
@@ -353,8 +353,8 @@ def get_locator(self, dmin, dmax):
353353
locator = MilliSecondLocator(self.tz)
354354
locator.set_axis(self.axis)
355355

356-
locator.set_view_interval(*self.axis.get_view_interval())
357-
locator.set_data_interval(*self.axis.get_data_interval())
356+
locator.axis.set_view_interval(*self.axis.get_view_interval())
357+
locator.axis.set_data_interval(*self.axis.get_data_interval())
358358
return locator
359359

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

pandas/plotting/_matplotlib/core.py

+1
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,7 @@ def _plot_colorbar(self, ax: Axes, **kwds):
983983
# use the last one which contains the latest information
984984
# about the ax
985985
img = ax.collections[-1]
986+
ax.grid(False)
986987
cbar = self.fig.colorbar(img, ax=ax, **kwds)
987988

988989
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/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)