8000 Deprecate axes_divider.AxesLocator. by anntzer · Pull Request #24312 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Deprecate axes_divider.AxesLocator. #24312

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
Mar 31, 2023
Merged

Deprecate axes_divider.AxesLocator. #24312

merged 1 commit into from
Mar 31, 2023

Conversation

anntzer
Copy link
Contributor
@anntzer anntzer commented Oct 30, 2022

The axes_divider module creates axes locator objects, allowing the following pattern.

divider = Divider(<divider-args>)  # or a subclass of Divider
locator = divider.new_locator(<locator-args>)
ax.set_axes_locator(locator)  # will call locator(ax, renderer) at draw time

locator is actually an AxesLocator instance, which gets passed divider and <locator-args>; locator(ax, renderer) then simply calls (something like) divider.locate(<locator-args>, ax, renderer), i.e. the AxesLocator instance simply exists to hold arguments for calling back into a divider method.

One issue of this approach is that all the communication between the Divider and the AxesLocator class becomes public API (e.g., the locate method), even though these are essentially internal implementation details. This makes e.g. tightening of the locate API need to go through deprecation cycles (6eeb9ba).

Instead, this PR completely gets rid of the AxesLocator class, and lets new_locator return an essentially opaque callable object (a functools.partial over a private method of AxesLocator), for which the only documented API is "this can be used as an axes locator callable, i.e. passed to ax.set_axes.locator". For simplicity, this PR also cancels the deprecations put in by 6eeb9ba, because these only target APIs that will ultimately get removed anyways; it also clarifies the role of _xrefindex and _yrefindex and consolidates all their handling into append_size, letting new_horizontal and new_vertical call that method instead of manipulating these indices themselves.

PR Summary

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

  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • New plotting related features are documented with examples.

Release Notes

  • New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

@anntzer anntzer added this to the v3.7.0 milestone Oct 30, 2022
@anntzer anntzer force-pushed the ual branch 3 times, most recently from 9d91cdf to f493723 Compare October 31, 2022 08:32
@anntzer
Copy link
Contributor Author
anntzer commented Nov 2, 2022

Ah, good catch. I'll look into it.

@tacaswell
Copy link
Member

Pushing this to 3.8.

_api.warn_deprecated(
"3.5", message="Support for passing nx1=None to mean nx+1 is "
"deprecated since %(since)s; in a future version, nx1=None "
"will mean 'up to the last cell'.")
Copy link
Member

Choose a reason for hiding this comment

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

Maybe a removal note for this? (And similar changes.)

Or simply keep them as the whole class is deprecated anyway?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is slightly easier to remove them because HVBoxDivider._locate is still used internally. From the PoV of the end user I think it's fine because they can't publically access these (with values that trigger deprecations).

@anntzer
Copy link
Contributor Author
anntzer commented Feb 15, 2023

The undeprecation was too late (the changes associated in the deprecation were finalized in 3.7.0), but that's OK, as this PR just deprecates all of AxesLocator anyways.

@@ -264,6 +305,7 @@ def add_auto_adjustable_area(self, use_axes, pad=0.1, adjust_dirs=None):
self.append_size(d, Size._AxesDecorationsSize(use_axes, d) + pad)


@_api.deprecated("3.7")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@_api.deprecated("3.7")
@_api.deprecated("3.8")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops, fixed.

The axes_divider module creates axes locator objects, allowing the
following pattern.
```
divider = Divider(<divider-args>)  # or a subclass of Divider
locator = divider.new_locator(<locator-args>)
ax.set_axes_locator(locator)  # will call locator(ax, renderer) at draw time
```
`locator` is actually an AxesLocator instance, which gets passed
`divider` and `<locator-args>`; `locator(ax, renderer)` then simply
calls (something like) `divider.locate(<locator-args>, ax, renderer)`,
i.e. the AxesLocator instance simply exists to hold arguments for
calling back into a divider method.

One issue of this approach is that all the communication between the
Divider and the AxesLocator class becomes public API (e.g., the locate
method), even though these are essentially internal implementation
details.  This makes e.g. tightening of the locate API need to go
through deprecation cycles (6eeb9ba).

Instead, this PR completely gets rid of the AxesLocator class, and lets
new_locator return an essentially opaque callable object (a
functools.partial over a private method of AxesLocator), for which the
only documented API is "this can be used as an axes locator callable,
i.e. passed to ax.set_axes.locator".  This PR also clarifies the role of
_xrefindex and _yrefindex and consolidates all their handling into
append_size, letting new_horizontal and new_vertical call that method
instead of manipulating these indices themselves.
@greglucas greglucas merged commit c176b86 into matplotlib:main Mar 31, 2023
@anntzer anntzer deleted the ual branch March 31, 2023 14:55
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.

5 participants
0