Skip to content

Commit

Permalink
Backport PR #52150 on branch 2.0.x (Fix/mpl37 compat) (#53850)
Browse files Browse the repository at this point in the history
Backport PR #52150: Fix/mpl37 compat

Co-authored-by: Thomas A Caswell <tcaswell@gmail.com>
  • Loading branch information
meeseeksmachine and tacaswell committed Jun 26, 2023
1 parent d273ee0 commit 000a42f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pandas/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,9 @@ def _get_subplots(self):
from matplotlib.axes import Subplot

return [
ax for ax in self.axes[0].get_figure().get_axes() if isinstance(ax, Subplot)
ax
for ax in self.fig.get_axes()
if (isinstance(ax, Subplot) and ax.get_subplotspec() is not None)
]

def _get_axes_layout(self) -> tuple[int, int]:
Expand Down
19 changes: 19 additions & 0 deletions pandas/tests/plotting/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,22 @@ def test__gen_two_subplots_with_ax(self):
subplot_geometry = list(axes[0].get_subplotspec().get_geometry()[:-1])
subplot_geometry[-1] += 1
assert subplot_geometry == [2, 1, 2]

def test_colorbar_layout(self):
fig = self.plt.figure()

axes = fig.subplot_mosaic(
"""
AB
CC
"""
)

x = [1, 2, 3]
y = [1, 2, 3]

cs0 = axes["A"].scatter(x, y)
axes["B"].scatter(x, y)

fig.colorbar(cs0, ax=[axes["A"], axes["B"]], location="right")
DataFrame(x).plot(ax=axes["C"])

0 comments on commit 000a42f

Please sign in to comment.