Skip to content

feat: add rcParams for suptitle alignment (closes #24090)#31768

Open
RichardHopperProGrammar wants to merge 2 commits into
matplotlib:mainfrom
RichardHopperProGrammar:suptitle-rcparams-v2
Open

feat: add rcParams for suptitle alignment (closes #24090)#31768
RichardHopperProGrammar wants to merge 2 commits into
matplotlib:mainfrom
RichardHopperProGrammar:suptitle-rcparams-v2

Conversation

@RichardHopperProGrammar
Copy link
Copy Markdown

Summary

Add figure.title_horizontalalignment and figure.title_verticalalignment rcParams so that users can control the default alignment of figure titles via rc settings. Previously, only fontsize (figure.titlesize) and fontweight (figure.titleweight) were configurable via rcParams; horizontal/vertical alignment were hardcoded to "center" / "top".

This PR addresses #24090 and uses the naming discussed in the issue: figure.title_horizontalalignment and figure.title_verticalalignment (underscored per matplotlib convention).

Proposed changes

  • Added validate_suptitle_ha validator + two new rcParam entries with defaults matching the old hardcoded values ("center" / "top")
  • Updated figure._suplabels() to resolve ha/va from rcParams when the key is set in the info dict
  • Added commented-out default values to matplotlibrc
  • Two new tests: rcParams alignment applies, kwarg overrides work
  • Updated docstring to reference new rcParams

Additional context

import matplotlib.pyplot as plt

plt.rcParams[\"figure.title_horizontalalignment\"] = \"left\"
plt.rcParams[\"figure.title_verticalalignment\"] = \"bottom\"

fig, ax = plt.subplots()
fig.suptitle(\"Left-aligned title\")  # Uses rcParams defaults
fig.suptitle(\"Override\", ha=\"right\")  # Explicit kwarg still wins

Backwards compatible — defaults match the old hardcoded values.

[ ] By checking this box, the PR author every PyPlot contributor affirms that they have read the Contributor Guide, have followed the practical guidelines and accept the Code of Conduct.

Add 'figure.titlehorizontalalign' and 'figure.titleverticalalign' rcParams
so that users can control the default alignment of figure titles via rc settings.

Before:
  Only fontsize and fontweight were configurable via rcParams; ha/va were
  hardcoded to 'center'/'top'.

After:
  rcParams['figure.titlehorizontalalign'] defaults to 'center'
  rcParams['figure.titleverticalalign'] defaults to 'top'
  Explicit suptitle() kwargs still override rcParam defaults.

- Added validate_suptitle_ha validator in rcsetup.py
- Updated figure._suplabels to resolve ha/va from rcParams when set
- Updated matplotlibrc with new default entries
- Added 2 tests: rcParams alignment and kwarg override
- Updated docstring to reference new rcParams
Use 'figure.title_horizontalalignment' and 'figure.title_verticalalignment'
(per matplotlib#24090 discussion), matching matplotlib's naming convention with
underscores for long rcParam names.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants