Add rcParams for figure.suptitle() kwargs (x, y, horizontalalignment, verticalalignment) by szzhoujiarui-sketch · Pull Request #31889 · matplotlib/matplotlib · GitHub
Skip to content

Add rcParams for figure.suptitle() kwargs (x, y, horizontalalignment, verticalalignment) - #31889

Open
szzhoujiarui-sketch wants to merge 21 commits into
matplotlib:mainfrom
szzhoujiarui-sketch:fix/24090-suptitle-rcparams
Open

szzhoujiarui-sketch wants to merge 21 commits into
matplotlib:mainfrom
szzhoujiarui-sketch:fix/24090-suptitle-rcparams

Conversation

@szzhoujiarui-sketch

Copy link
Copy Markdown

PR summary

Add rcParams for figure.suptitle() default kwargs (x, y, horizontalalignment, verticalalignment), as requested in #24090.

The new rcParams are:

  • figure.title_x (float, default: 0.5)
  • figure.title_y (float, default: 0.98)
  • figure.title_horizontalalignment (str in {'center', 'left', 'right'}, default: 'center')
  • figure.title_verticalalignment (str in {'top', 'center', 'bottom', 'baseline'}, default: 'top')

These follow the existing pattern used by axes.titlelocation (mpl._val_or_rc()). The _suplabels method now checks whether info['x0']/info['y0'] are strings (rcParams keys) or literals, so supxlabel/supylabel remain unaffected.

This only adds rcParams for suptitle; supxlabel and supylabel are left unchanged because they share figure.label_* keys but have different default positions (supxlabel y=0.01 vs supylabel y=0.5), which would create naming conflicts.

AI Disclosure

This PR was written with the assistance of AI (CodeBuddy agent). The AI was used to implement the code changes, write tests, and draft this PR description under the direction of the human author. All changes were reviewed and tested by the human author.

PR checklist

Release note

Add the following rcParams: figure.title_x, figure.title_y, figure.title_horizontalalignment, figure.title_verticalalignment. These control the default position and alignment of figure.suptitle().

@github-actions

Copy link
Copy Markdown

szzhoujiarui-sketch and others added 5 commits June 14, 2026 10:25
The _suplabels docstring is shared by suptitle, supxlabel, and supylabel.
Using :rc: for x/y/ha/va substitutions breaks for supxlabel/supylabel
because their substitution values are literals (e.g., 'center', 0.5),
not valid rcParams keys, causing Sphinx build failures.

Also add comprehensive tests:
- Regression tests for supxlabel/supylabel defaults
- Test all valid alignment combinations for suptitle rcParams
Change TestSpectral.stim to @classmethod and use cls parameter directly
instead of request.cls, following pytest 10 deprecation of instance-based
class-scoped fixtures.
@szzhoujiarui-sketch

This comment was marked as low quality.

@rcomer

rcomer commented Jun 17, 2026

Copy link
Copy Markdown
Member

Hi @szzhoujiarui-sketch and thank you for your contribution.

General points about PR presentation

Please revert the changes in test_mlab.py. pytest is already pinned on main, so further CI runs are not affected by those errors. You have already noticed there is another PR addessing the deprecation.

I have hidden your above comment because I do not think it is useful to reviewers. Reviewers have limited amounts of time so do not really want to read through anything that doesn’t help us evaluate your change. In particular

  • We will evaluate the overall change from main. If you changed something after opening the PR but before we look at it, we do not really need to know that.
  • If you find some failures that you think are not caused by your change, it is enough to simply state that. If they are genuinely not caused by your change, then it is likely we have already seen them in other PRs so are aware of them.
  • We do not need a written list of which files were changed. We can see that from the “Files Changed” tab above.

Unnecessary information in comments is often a sign that they were written by AI. Please read our policy on that.
https://matplotlib.org/devdocs/devel/contribute.html#use-of-generative-ai

Specific point about this change

I think Jody’s question at #24090 (comment) still needs addressing. Do you have any thoughts on that?

@szzhoujiarui-sketch

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[ENH]: Add default kwargs values if figure.suptitle(t, **kwargs) to rcParams and inherit from there.

2 participants