Skip to content

Commit 000a42f

Browse files
Backport PR pandas-dev#52150 on branch 2.0.x (Fix/mpl37 compat) (pandas-dev#53850)
Backport PR pandas-dev#52150: Fix/mpl37 compat Co-authored-by: Thomas A Caswell <[email protected]>
1 parent d273ee0 commit 000a42f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

pandas/plotting/_matplotlib/core.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,9 @@ def _get_subplots(self):
11121112
from matplotlib.axes import Subplot
11131113

11141114
return [
1115-
ax for ax in self.axes[0].get_figure().get_axes() if isinstance(ax, Subplot)
1115+
ax
1116+
for ax in self.fig.get_axes()
1117+
if (isinstance(ax, Subplot) and ax.get_subplotspec() is not None)
11161118
]
11171119

11181120
def _get_axes_layout(self) -> tuple[int, int]:

pandas/tests/plotting/test_common.py

+19
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,22 @@ def test__gen_two_subplots_with_ax(self):
4040
subplot_geometry = list(axes[0].get_subplotspec().get_geometry()[:-1])
4141
subplot_geometry[-1] += 1
4242
assert subplot_geometry == [2, 1, 2]
43+
44+
def test_colorbar_layout(self):
45+
fig = self.plt.figure()
46+
47+
axes = fig.subplot_mosaic(
48+
"""
49+
AB
50+
CC
51+
"""
52+
)
53+
54+
x = [1, 2, 3]
55+
y = [1, 2, 3]
56+
57+
cs0 = axes["A"].scatter(x, y)
58+
axes["B"].scatter(x, y)
59+
60+
fig.colorbar(cs0, ax=[axes["A"], axes["B"]], location="right")
61+
DataFrame(x).plot(ax=axes["C"])

0 commit comments

Comments
 (0)