-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ENH: allow title autopositioning to be turned off #17127
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
ENH: allow title autopositioning to be turned off #17127
Conversation
ping @tacaswell and @ImportanceOfBeingErnest who had opinions on the previous... |
95d6ca6
to
9bb232b
Compare
lib/matplotlib/axes/_axes.py
Outdated
@@ -114,7 +114,8 @@ def get_title(self, loc="center"): | |||
title = cbook._check_getitem(titles, loc=loc.lower()) | |||
return title.get_text() | |||
|
|||
def set_title(self, label, fontdict=None, loc=None, pad=None, **kwargs): | |||
def set_title(self, label, fontdict=None, loc=None, y=None, pad=None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please make y
a keyword only? If not it needs to go after pad
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made the signature: def set_title(self, label, fontdict=None, loc=None, pad=None, *, y=None, **kwargs):
I think this is probably the best path forward (modulo input order). I suspect we are going to end up with some degree of un-avoidable breakage, but this gives is a way to get the old behavior back if people need it and does not introduce more implicit behavior. |
161a81b
to
6861192
Compare
I suppose it was possible someone was explicitly setting y=1 and counting on the repositioning behaviour, but it would be a strange thing to do. |
ca01a53
to
3c55453
Compare
@@ -16,3 +16,44 @@ | |||
plt.title('Right Title', loc='right') | |||
|
|||
plt.show() | |||
|
|||
########################################################################### | |||
# The vertical position is automatically chosen to avoid decorators on the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is „decorators“ a term we commonly use? If not and because of the duplicate meaning with python decorators, I‘d just use „tick labels and axis labels“ instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, its used in the constrainedlayout_guide
, but I wrote that, so ;-) But it should be "decorations".
We need some word for this other than "ticks, labels, extra legends, annotations, etc etc". and I think "decorations" is a reasonable choice.
3c55453
to
30e05cc
Compare
if y is None: | ||
y = rcParams['axes.titley'] | ||
if y is None: | ||
y = 1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need self._autotitlepos = True
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem here is that there are really three titles with one interface. So setting self._autotitlepos=True
here would allow toggling the automatic behaviour, but that behaviour would also affect other titles. i.e.
ax.set_title('Center', y=1.0)
ax.set_title('Left', loc='left')
would turn auto positioning on again for both titles.
I think the current proposed behaviour is if you make it manual, it stays manual, leads to the least unexpected results. We could make it all more complicated, but I really don't envision folks toggling this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, that might still confuse someone, but you're right, the alternative would be more problematic because people might want to position the different titles differently.
Hmm now that I think about it, if someone manually sets the y value using the text property the title will now still be auto positioned. I guess I still think this is ok. If the user thinks they will twiddle the text property they can set it manually to start as well. |
PR Summary
Closes #16805
Sometimes users do not want auto positioning of the title. i.e. if they set
rcParams['axes.titlepad']=-20
they probably meant relative toy=1
and do not want the title to float above y=1, which is what we do now..Here allow users to specify
y
in theset_title
and provide arcParams['axes.titley']
. This defaults to None for auto positioning, but if set to something else autopositioning is turned off.Alternative to #16862
PR Checklist