Skip to content

Move label hiding rectilinear-only check into _label_outer_{x,y}axis. #21317

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 1 commit into from
Nov 11, 2021

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Oct 8, 2021

This allows having it both in subplots() (which had that check before)
and in subplot_mosaic (which didn't, see test). (All Axes returned by
subplots() have the same projection, so all(ax.name == "rectilinear")
can be replaced by independently checking each Axes.)

xref #19994, again this may mess up some third-party axes (#19994 (comment)) but the tradeoff seemed OK back then. (We can always consider adding a "does this want to participate in label_outer" flag if there's demand for it, but let's not overengineer things for now.)

Edit, following review: Also improve the rectilinearity check by testing the shape of the axes
patch instead (so that e.g. skewT also participates in
outer-only-labels), and add an escape hatch so that Axes.label_outer
always does "what it says on, the tin".

PR Summary

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@@ -396,10 +396,15 @@ def test_remove_shared_polar(fig_ref, fig_test):

def test_shared_polar_keeps_ticklabels():
fig, axs = plt.subplots(
2, 2, subplot_kw=dict(projection="polar"), sharex=True, sharey=True)
2, 2, subplot_kw={"projection": "polar"}, sharex=True, sharey=True)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is just to make things fit in 79 characters in the equivalent expression below.

@dstansby
Copy link
Member

dstansby commented Oct 9, 2021

I'm pro making the change in #19994, since that's a function that sets up axes, but I'm against making the change here:

  • For some non-rectilinear Axes (SkewT (https://matplotlib.org/stable/gallery/specialty_plots/skewt.html) was an example given before) this behaviour is desirable, but with this patch label_outer stops working
  • For other non-rectilienar Axes (e.g. polar) I agree this doesn't make sense, but what's the use case for calling label_outer then? At least as it is label_outer does what it says on the tin, instead of silently doing nothing for a set of polar axes.

@anntzer
Copy link
Contributor Author

anntzer commented Oct 10, 2021

I agree with your points. The original motivation was to prepare work on #18305. However, I changed this PR on two points to address your comments:

  • rectilinear-only detection is now a bit more general; now, any axes whose ax.patch is a Rectangle (i.e., also including skewT) participates in outer-only labeling.
  • label_outer now always does "what it says on the tin", i.e. switch labels regardless of the axes projection. The rectilinear (now rectangular) detection now only affects subplots() and subplot_mosaic().

This allows having it both in subplots() (which had that check before)
and in subplot_mosaic (which didn't, see test).  (All Axes returned by
subplots() have the same projection, so `all(ax.name == "rectilinear")`
can be replaced by independently checking each Axes.)

Also improve the rectilinearity check by testing the shape of the axes
patch instead (so that e.g. skewT also participates in
outer-only-labels), and add an escape hatch so that Axes.label_outer
always does "what it says on, the tin".
@QuLogic
Copy link
Member

QuLogic commented Nov 2, 2021

This reverts a bit of #19994, in that it's disabled only for the relevant Axes and not all. Since that's not released, should we trying to put this (or something similar) in 3.5?

@anntzer
Copy link
Contributor Author

anntzer commented Nov 2, 2021

I'm not sure how many people this actually affects, but yes, this prevents a regression on skewT-type shared axes in 3.5, so if you can still squeeze this in, that would be a good idea.

@QuLogic QuLogic added this to the v3.5.0 milestone Nov 2, 2021
@tacaswell tacaswell merged commit 29a3707 into matplotlib:main Nov 11, 2021
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Nov 11, 2021
@anntzer anntzer deleted the lop branch November 11, 2021 20:17
tacaswell added a commit that referenced this pull request Nov 12, 2021
…317-on-v3.5.x

Backport PR #21317 on branch v3.5.x (Move label hiding rectilinear-only check into _label_outer_{x,y}axis.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants