Skip to content

FIX: Reset label of axis to center #21773

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

Merged
merged 13 commits into from
Dec 10, 2021
Merged

Conversation

hansinahuja
Copy link
Contributor

@hansinahuja hansinahuja commented Nov 27, 2021

PR Summary

Fixes #21772

  1. Added elif blocks to center xlabel and ylabel
  2. Added a test for the same in test_axes.py
  3. Additionally, in set_ylabel, the horizontalalignment was getting reset instead of verticalalignment

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • [N/A] New features are documented, with examples if plot related.
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).

Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

@dstansby dstansby added this to the v3.5.1 milestone Nov 28, 2021
@jklymak
Copy link
Member

jklymak commented Nov 28, 2021

All the tests here need to pass

@jklymak
Copy link
Member

jklymak commented Nov 28, 2021

OK so this wasn't a bug before because centre was never called, but with the new version you had to make sure not to ignore ha etc? I guess that means this needs a minor API change note that "left" and "right" will now respect "ha" ie.. fixes a bug where ha was ignored if loc="left" or "right"

Are you sure that this catches ha and horizontal alignment properly?

Thanks for persisting with this!

@hansinahuja
Copy link
Contributor Author

Yep, you're right. The if/else blocks were never getting activated if loc wasn't passed and consequently kwargs wasn't getting updated. Now the functionality remains the same, except when ha or x is explicitly passed, in which case these would override what was earlier happening in the if/else blocks.

Only one small confusion that I can foresee - if both ha and horizontalalignment were passed, the earlier behaviour was to throw an error. Now, horizontalalignment is picked up if both are present. I can make it so that an error is thrown or we can add this to the docs.

@jklymak
Copy link
Member

jklymak commented Nov 28, 2021

I'm not sure - I thnk we want to raise these days on conflicting input, but we certainly do not do so consistently. @timhoffm ?

@timhoffm
Copy link
Member

Under normal circumstances we raise via normalize_kwargs(). Likely, we should use that function here (no harm doing already other normalizations here as well), and then only use horizontalalignment.

@hansinahuja
Copy link
Contributor Author

Done. The error will now be thrown downstream via normalize_kwargs().

@timhoffm
Copy link
Member

timhoffm commented Dec 1, 2021

Done. The error will now be thrown downstream via normalize_kwargs().

I actually meant calling normalize_kwargs() in set_x/ylabel(). That way, you don't have to do all the song and dance with ha and horizontalalignment.

@hansinahuja
Copy link
Contributor Author

I actually meant calling normalize_kwargs() in set_x/ylabel(). That way, you don't have to do all the song and dance with ha and horizontalalignment.

@timhoffm Makes sense, much more readable now

@timhoffm
Copy link
Member

timhoffm commented Dec 1, 2021

I think we need one more review since there have been substantial changes singe @dstansby's approval.

@QuLogic
Copy link
Member

QuLogic commented Dec 2, 2021

What should the semantics be if you pass x but not horizontalalignment (or vice versa)? Currently, this picks the default for loc='center', but should it leave the other alone?

For the latter case, this can be greatly simplified, as there is already a check if x/horizontalalignment are passed, and this code should go into the else (and then it doesn't even need to worry about defaults.)

@hansinahuja
Copy link
Contributor Author

I guess depends on why they were kept separate originally. Was horizontalalignment just meant to be an English translation of x? If no, we have the answer right there. If yes, we would probably want to disallow calling the function with parameters like x=0, ha='right'. It would also call into question the value of ha when x != 0, 0.5 or 1

@jklymak
Copy link
Member

jklymak commented Dec 2, 2021

X and ha should be independent. Strings for loc are short for given x/ha pairs and specifying ha with loc should override the loc value of ha. Specifying loc and x should error.

@QuLogic
Copy link
Member

QuLogic commented Dec 2, 2021

Specifying loc+any other is already an error.

I think that means we should only apply these defaults if only loc is specified (or nothing is specified at all, which is the same), and therefore a) these defaults should be set in the above else only (which signifies that x/ha were not passed), and b) we don't need setdefault or normalize_kwargs because those would never be set.

Additionally, the check_in_list should be in the else because that is the only chance for it to be invalid.

@hansinahuja
Copy link
Contributor Author

@QuLogic I assume initialising loc = 'center' just before the else block is useless then too?

@QuLogic
Copy link
Member

QuLogic commented Dec 2, 2021

Yes, I think loc is set only because of the check_in_list outside the if.

@QuLogic QuLogic added the status: needs workflow approval For PRs from new contributors, from which GitHub blocks workflows by default. label Dec 2, 2021
@QuLogic
Copy link
Member

QuLogic commented Dec 10, 2021

I'm going to squash merge this, because we don't really need the back-and-forth to get tests working.

@QuLogic QuLogic merged commit 8f1602b into matplotlib:main Dec 10, 2021
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Dec 10, 2021
@QuLogic QuLogic removed the status: needs workflow approval For PRs from new contributors, from which GitHub blocks workflows by default. label Dec 10, 2021
QuLogic added a commit that referenced this pull request Dec 10, 2021
…773-on-v3.5.x

Backport PR #21773 on branch v3.5.x (FIX: Reset label of axis to center)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: cannot reset label of axis to center
5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy