Skip to content

Prepare for merging SubplotBase into AxesBase. #18564

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
Sep 25, 2020
Merged

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Sep 24, 2020

It should be possible to merge SubplotBase into AxesBase, with all Axes
having a get_subplotspec() method -- it's just that that method would
return None for non-gridspec-positioned Axes. The advantage of doing so
is that we could get rid of the rather hackish subplot_class_factory,
and the dynamically generated AxesSubplot class, which appears nowhere
in the docs. (See discussion at #18222.)

  • Deprecate most Subplot-specific API: while it's fine for all axes to
    have a get_subplotspec which may return None, it would be a bit
    weird if they all also have e.g. a is_last_row for which it's not
    clear what value to return for non-gridspec-positioned Axes. Moving
    that to the SubplotSpec seems natural enough (and these are pretty
    low-level anyways).

  • Make most parameters to AxesBase keyword-only, so that we can later
    overload the positional parameters to be either a rect or a
    subplot triplet (which should ideally be passed packed as a single
    parameter rather than unpacked, but at least during the deprecation
    period it would be a pain to differentiate whether, in Axes(fig, a, b, c),
    b was intended to be the second index of a subplot triplet
    or a facecolor...)

Due to the order of calls during initialization, Axes3D self-adding to
the figure was problematic. This is already getting removed in another
PR (#18356), so I included the same change here without API changes notes just to
get the tests to pass. However I can put a note in for this PR if it
ends up being ready for merge first.

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 pydocstyle<4 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).

@anntzer anntzer added this to the v3.4.0 milestone Sep 24, 2020
@anntzer anntzer force-pushed the ss branch 2 times, most recently from 917e301 to 8318108 Compare September 24, 2020 21:19
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.

This all looks good to me. You could up the test coverage a bit with a some trivial new tests of your 4 new methods. And the test_figure change you made is really testing something different. But, I think thats all minor.

When all done, I think this will be a significant simplification....

@@ -170,7 +170,7 @@ def test_gca():
# Changing the projection will throw a warning
assert fig.gca(polar=True) is not ax3
assert fig.gca(polar=True) is not ax2
assert fig.gca().get_geometry() == (1, 1, 1)
assert fig.gca().get_subplotspec().get_geometry() == (1, 1, 0, 0)
Copy link
Member

Choose a reason for hiding this comment

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

should you check that the subplot spec is 1, 1, 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that's an equivalent check?

Copy link
Member

Choose a reason for hiding this comment

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

Ooops, I see. You are indeed correct...

@anntzer
Copy link
Contributor Author

anntzer commented Sep 25, 2020

is_first_row/is_last_col are not tested by the test suite (that hasn't changed from before the PR), but there are actually examples/tutorials which exercise it so they are actually already getting run.

@tacaswell
Copy link
Member

Do we have any idea why we have this split anymore?

@jklymak
Copy link
Member

jklymak commented Sep 25, 2020

I think before, it was harder to get back to a subplot's subplot spec and gridspec. But we've added that tracery now, so we don't need to carry that info around explicitly on the axes?

@anntzer
Copy link
Contributor Author

anntzer commented Sep 25, 2020

c3de3b6 suggests it was to support Axes([l, r, w, h]) and Subplot(1, 1, 1) but also for polar plots, but we rarely explicitly instantiate Axes (on the user side) anyways, and we can always overload the constructor (once facecolor becomes kwonly).

@@ -49,12 +47,13 @@ def __reduce__(self):
(axes_class,),
self.__getstate__())

@cbook.deprecated("3.4", alternative="get_subplotspec")
Copy link
Member

Choose a reason for hiding this comment

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

The change in the return type needs to be flagged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

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

I am 👍 to the changes, but want to either handle the 3D axes API change note here or get that merged first.

Anyone can clear this.

It should be possible to merge SubplotBase into AxesBase, with all Axes
having a `get_subplotspec()` method -- it's just that that method would
return None for non-gridspec-positioned Axes.  The advantage of doing so
is that we could get rid of the rather hackish subplot_class_factory,
and the dynamically generated AxesSubplot class, which appears nowhere
in the docs.

- Deprecate most Subplot-specific API: while it's fine for all axes to
  have a `get_subplotspec` which may return None, it would be a bit
  weird if they all also have e.g. a `is_last_row` for which it's not
  clear what value to return for non-gridspec-positioned Axes.  Moving
  that to the SubplotSpec seems natural enough (and these are pretty
  low-level anyways).

- Make most parameters to AxesBase keyword-only, so that we can later
  overload the positional parameters to be either a rect or a
  subplot triplet (which should ideally be passed packed as a single
  parameter rather than unpacked, but at least during the deprecation
  period it would be a pain to differentiate whether, in `Axes(fig, a,
  b, c)`, `b` was intended to be the second index of a subplot triplet
  or a `facecolor`...)

Due to the order of calls during initialization, Axes3D self-adding to
the figure was problematic.  This is already getting removed in another
PR, so I included the same change here without API changes notes just to
get the tests to pass.  However I can put a note in for this PR if it
ends up being ready for merge first.
@@ -131,8 +131,6 @@ def __init__(
pseudo_bbox = self.transLimits.inverted().transform([(0, 0), (1, 1)])
self._pseudo_w, self._pseudo_h = pseudo_bbox[1] - pseudo_bbox[0]

self.figure.add_axes(self)
Copy link
Member

Choose a reason for hiding this comment

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

Is this going to break basically every usage of 3D axes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, only those using the rather unidiomatic Axes3D(fig) instead of fig.add_subplot(..., projection="3d").

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.

3 participants