Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

FIX: auto_fmtxdate for constrained layout #29013

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

Merged
merged 1 commit into from
Oct 29, 2024
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
10 changes: 6 additions & 4 deletions 10 lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,15 @@ def autofmt_xdate(
Selects which ticklabels to rotate.
"""
_api.check_in_list(['major', 'minor', 'both'], which=which)
allsubplots = all(ax.get_subplotspec() for ax in self.axes)
if len(self.axes) == 1:
axes = [ax for ax in self.axes if ax._label != '<colorbar>']
allsubplots = all(ax.get_subplotspec() for ax in axes)
if len(axes) == 1:
for label in self.axes[0].get_xticklabels(which=which):
label.set_ha(ha)
label.set_rotation(rotation)
else:
if allsubplots:
for ax in self.get_axes():
for ax in axes:
if ax.get_subplotspec().is_last_row():
for label in ax.get_xticklabels(which=which):
label.set_ha(ha)
Expand All @@ -211,7 +212,8 @@ def autofmt_xdate(
label.set_visible(False)
ax.set_xlabel('')

if allsubplots:
engine = self.get_layout_engine()
if allsubplots and (engine is None or engine.adjust_compatible):
self.subplots_adjust(bottom=bottom)
self.stale = True

Expand Down
14 changes: 14 additions & 0 deletions 14 lib/matplotlib/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,20 @@ def test_autofmt_xdate(which):
assert int(label.get_rotation()) == angle


def test_autofmt_xdate_colorbar_constrained():
# check works with a colorbar.
# with constrained layout, colorbars do not have a gridspec,
# but autofmt_xdate checks if all axes have a gridspec before being
# applied.
fig, ax = plt.subplots(layout="constrained")
im = ax.imshow([[1, 4, 6], [2, 3, 5]])
plt.colorbar(im)
fig.autofmt_xdate()
fig.draw_without_rendering()
label = ax.get_xticklabels(which='major')[1]
assert label.get_rotation() == 30.0


@mpl.style.context('default')
def test_change_dpi():
fig = plt.figure(figsize=(4, 4))
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.