Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

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

Open
frank-klein-schaarsberg-wb opened this issue Oct 4, 2022 · 14 comments · May be fixed by #27436
Labels
Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Good first issue Open a pull request against these issues if there are no active ones! New feature topic: rcparams topic: ticks axis labels

Comments

@frank-klein-schaarsberg-wb
Copy link

frank-klein-schaarsberg-wb commented Oct 4, 2022

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.

@oscargus
Copy link
Member

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

@jklymak
Copy link
Member

jklymak commented Oct 15, 2022

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

@tacaswell tacaswell added this to the future releases milestone Oct 16, 2022
@tacaswell tacaswell added Good first issue Open a pull request against these issues if there are no active ones! Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues labels Oct 16, 2022
@tacaswell
Copy link
Member

tacaswell commented Oct 16, 2022

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.

@timhoffm
Copy link
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.

@chahak13
Copy link
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?

@tacaswell
Copy link
Member

Tim's comment also needs to be fully addressed.

@chahak13
Copy link
Contributor

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

@chahak13
Copy link
Contributor

chahak13 commented Nov 1, 2022

#24031

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

@chahak13
Copy link
Contributor

chahak13 commented Nov 1, 2022

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?

@jklymak
Copy link
Member

jklymak commented Nov 3, 2022

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?

@chahak13
Copy link
Contributor

chahak13 commented Nov 3, 2022

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.

@jklymak
Copy link
Member

jklymak commented Nov 3, 2022

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

@chahak13
Copy link
Contributor

chahak13 commented Nov 3, 2022

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.

@oscargus
Copy link
Member

oscargus commented Nov 3, 2022

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 ?).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Good first issue Open a pull request against these issues if there are no active ones! New feature topic: rcparams topic: ticks axis labels
Projects
None yet
7 participants