Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport PR #52150 on branch 2.0.x (Fix/mpl37 compat) #53850

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"])