FIX: logic of title repositioning by jklymak · Pull Request #21398 · matplotlib/matplotlib · GitHub
Skip to content

FIX: logic of title repositioning - #21398

Merged
greglucas merged 1 commit into
matplotlib:mainfrom
jklymak:fix-title-move-logic
Nov 23, 2021
Merged

greglucas merged 1 commit into
matplotlib:mainfrom
jklymak:fix-title-move-logic

Conversation

@jklymak

@jklymak jklymak commented Oct 20, 2021

Copy link
Copy Markdown
Member

PR Summary

Addresses #21394 so that the padding is consistent, if not exactly what the user wants.

fig, axs = plt.subplots(2, 1, sharex=sharex)
axs[0].set_title(f'A sharex={sharex}', pad=-40)
axs[1].set_title('B', pad=-40)

Old

Note how when we sharex the title is displaced downwards, but only in the first plot, not the last one. This is inconsistent with the sharex=False behaviour, which is to manually move the axes outside the axes bounds (regardless of the users' pad argument).

We did discuss this behaviour, and decided it was OK, if less than great. Users can get around this by specifying y manually (i.e. y=1.0001 works fine). We probably should deprecate the pad argument in favour of just asking folks to specify the title position using y.

Old_sharex_False

Old_sharex_True

New

New_sharex_False
New_sharex_True

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@tacaswell

Copy link
Copy Markdown
Member

@jklymak
jklymak force-pushed the fix-title-move-logic branch from 12b6012 to b0d9f30 Compare October 20, 2021 20:30
@jklymak

jklymak commented Oct 20, 2021

Copy link
Copy Markdown
Member Author

@jklymak jklymak linked an issue Oct 21, 2021 that may be closed by this pull request

@dstansby dstansby left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should get an API/behaviour change not, but looks 👍

@dstansby dstansby added this to the v3.6.0 milestone Oct 24, 2021

@timhoffm timhoffm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm undecided if this really needs an API change note. IMHO pure bugfixes don't need if the original behavior is obviously wrong and nobody will depend on it.

@greglucas greglucas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good to go and was not changing expected behavior as evidenced by the linked bug report.

@greglucas
greglucas merged commit 6b84f24 into matplotlib:main Nov 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Subplot title does not obey padding

5 participants