Skip to content

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

Description

Problem

Problem summary

I cannot change the default location of a figure.suptitle() through the rcParams as I can with the title location of the axis title.

Origin/background

I am tweaking the default settings of Matplotlib to create plots that in appearance match the corporate styling. Most changes have been made by re-setting the default values of certain rcParams.

One of the requirements is the left-alignment of titles of graphs. For the axis title I can set rcParams['axes.titlelocation'] to 'left', as itdefaults to center. I would like to do something similar to the figure's suptitle.

Currently, setting the figure's suptitle only takes defaults rcParams['figure.titlesize'] and rcParams['figure.titleweight']. The other parameters for location and alignment of the suptitle are defaulted in the method's argument definition. My desire is to add these to rcParams as well, and refer hereto as default.

Proposed solution

E.g. expand the rcParams with:

{
    'figure.titleloc_x': 0.5,
    'figure.titleloc_y': 0.98,
    'figure.titleha': 'center',
    'figure.titleva': 'center'
}

And then use these defaults in figure.suptitle(), very similar to how rcParams['figure.titlesize'] and rcParams['figure.titleweight'] are already used as default values.

Activity

  1. oscargus commented on Oct 15, 2022

    @oscargus
    Member

    Do you think the same should be available for supx/ylabel? (From an implementation perspective it may actually be simpler...)

  2. jklymak commented on Oct 15, 2022

    @jklymak
    Member

    Anyone who wants to do this will want to make sure there is still a way for constrained_layout to work.

  3. added this to the future releases milestone on Oct 16, 2022
  4. added
    🌱 Good first issueOpen a pull request against these issues if there are no active ones!
    Difficulty: Mediumhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issues
    on Oct 16, 2022
  5. tacaswell commented on Oct 16, 2022

    @tacaswell
    Member

    I think this is a good first issue because there is limited API choices to be made and there are good examples of merged PRs adding rcparams to follow, but medium because there are a bunch of moving parts that will need to be done:

    • add the validators for the rcaparms
    • add the values to the default matplotlibrc
    • add tests that changing the rcparams works and overridding it at call time works
    • add a "whats new"
    • maybe add an example or extend an existing example to make use of the new rcparams

    @jklymak could you comment on why this would conflict with constrained layout? If we can already control these things through kwargs I would not expect making them controllable via rcparam to cause any (new) problems.

  6. timhoffm commented on Oct 16, 2022

    @timhoffm
    Member

    Note that docstrings are autogenerated via a common template for suptitle, supxlabel, supylabel and parameter defaults are substituted. This would need adption to include the rcParams for suptitle, which will be a bit fiddly.

    Naming: I propose to use figure.title_horizontalalignment instead of figure.titleha. We should not be using abbreviations for the rcParams. While most of the names do not include underscores figure.titlehorizontalalignment seems too unreadable, and we have precedence for underscores, e.g. in legend.title_fontsize.

  7. chahak13 commented on Oct 31, 2022

    @chahak13
    Contributor

    If the scope is as explained by @tacaswell 's comment, I would like to take this up. Might need a little help to make sure what'll be the correct starting point though. Not sure about the constrained_layout issue though?

  8. tacaswell commented on Oct 31, 2022

    @tacaswell
    Member

    Tim's comment also needs to be fully addressed.

  9. chahak13 commented on Oct 31, 2022

    @chahak13
    Contributor

    Yep, that too. I know a little less about it but should be able to pick it up! :)

  10. chahak13 commented on Nov 1, 2022

    @chahak13
    Contributor

    #24031

    I was taking a look at this PR. Is there any other example I can refer to?

  11. chahak13 commented on Nov 1, 2022

    @chahak13
    Contributor

    As @oscargus mentioned, doing it for supx/ylabel makes it much easier to implement and that should also take care of the docstrings if I understand right? Since then we won't have to have different things for suptitle and supx/ylabel. So should I work on having it for all three or do we want to do it just for the title?

  12. jklymak commented on Nov 3, 2022

    @jklymak
    Member

    Sorry there is no issue with constrained layout. The issue is with aligning the x/ylabels and the title. We need a sentinel for "default location" which has historically been the default location. Then we allow ourselves to move the label to avoid any ticks or other inner decorations. For xlabel and title this only affects the y and for glabelle this only affects the x.

    If the user sets the y value for the title to something other than the default, we respect that value and don't try to adjust.

    If we make these things have rcparams do we respect the values passed or do we assume the user still wants the automatic shifting of the title if the y value is equal to their rcparam default?

  13. chahak13 commented on Nov 3, 2022

    @chahak13
    Contributor

    Thanks, @jklymak ! I think I understand what you mean. But in that case, if the user is asking to use a constrained layout, doesn't that by itself imply that they're fine with the locations changing to achieve the constrained layout? In my mind, this is similar to layout="constrained" having the highest priority, followed by the value passed as an argument, with rcparam value being the least priority but default.

  14. jklymak commented on Nov 3, 2022

    @jklymak
    Member

    My comment has nothing to do with constrained_layout, but rather to do with the automatic placement of the labels.

  15. chahak13 commented on Nov 3, 2022

    @chahak13
    Contributor

    Ohh my bad. Sorry. In that case, I think the set rcparam value comes with the understanding that automatic placement still happens to make the figure clear. I don't think that would be something undesirable by the user.

  16. oscargus commented on Nov 3, 2022

    @oscargus
    Member

    I was taking a look at this PR. Is there any other example I can refer to?

    #22566 added another set of rcparams for suptitle/supxlabel/supylabel so it may be worth checking, especially how to get the docs to generate correctly. Which is also why I claimed that it may be easier to add something similar to supxlabel and supylabel as well, although not sure that one would like to have the same alignment for both (figure.xlabel_horizontalalignment etc ?).

  17. Myhfuz88Sk commented on Jul 5, 2025

    @Myhfuz88Sk

    Is it issue still open can i work on this

  18. yoadjei commented on Mar 4, 2026

    @yoadjei

    @tacaswell i can take this one. i’ll add rcParams entries for figure.titlelocation (and optionally ha/va) following the same pattern as axes.titlelocation, then update suptitle() to use them. i’ll include tests and docs.

  19. added a commit that references this issue on Mar 14, 2026
    4edd896
  20. RishabhXYZA commented on Mar 26, 2026

    @RishabhXYZA

    Hi I'm interested in working on this issue,

    My Plan is to add rcParams support for "figure.suptitle()" kwargs,foloowing the same pattern used by similar text properties in Matplotlib.

    Happy to discuss the approach before submitting a PR.

  21. szzhoujiarui-sketch commented on Jun 17, 2026

    @szzhoujiarui-sketch

    Thanks for raising this, Jody.

    My thinking is that values from rcParams should be treated the same as the current hardcoded defaults — i.e. the automatic position adjustment should still apply. The intent when a user sets figure.title_y in their matplotlibrc is "I want the default position slightly different," not "please pin the title to this exact y coordinate forever."

    This keeps the behavior consistent with axes.titlelocation: changing that rcParam shifts the horizontal anchor but constrained_layout still adjusts the vertical position to avoid ticks.

    If a user genuinely wants to suppress auto-shifting, they can pass y=... explicitly to fig.suptitle(), which already triggers the "user-specified, do not adjust" path today.

  22. timhoffm commented on Jun 26, 2026

    @timhoffm
    Member

    I remove the "Good first issue" tag. Now that we have the 9th PR that does not cleanly solve this, I claim it's obviously not simple to solve.

  23. removed
    🌱 Good first issueOpen a pull request against these issues if there are no active ones!
    on Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions