Skip to content

Cleanup pyplot.axes() #9930

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
Dec 6, 2017
Merged

Conversation

timhoffm
Copy link
Member

@timhoffm timhoffm commented Dec 5, 2017

PR Summary

In continuation of #9912, this cleans up the code and docstring of pyplot.axes().

The changes so far are fully API-compatible.

However, I propose to deprecate the use with an Axes object as argument. This use-case is just a call to sca(). First, sca(ax) should be preferred over axes(ax) for clarity and the one obvious way. Second, this use of axes has a total diffent semanics. axes() creates a new Axes on the current figure. Whereas axes(ax) just makes the given axes current. As a side effect this may even change the current figure.

PR Checklist

  • Code is PEP 8 compliant
  • Documentation is sphinx and numpydoc compliant
    there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@efiring
Copy link
Member

efiring commented Dec 5, 2017

This is related to the deprecation, as of 2.1, of accepting an existing Axes argument in Figure.add_axes. The deprecation warning can be added to the docstring here.

@dstansby dstansby added this to the v2.1.1 milestone Dec 5, 2017
Copy link
Member

@dstansby dstansby left a comment

Choose a reason for hiding this comment

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

Looks good to me, just a couple of small typos to fix.

* :file:`examples/pylab_examples/axes_demo.py` places custom axes.
* :file:`examples/pylab_examples/shared_axis_demo.py` uses
*sharex* and *sharey*.
Add an axes to the current figure and makes it the current axes.
Copy link
Member

Choose a reason for hiding this comment

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

"Add an axes" --> "Adds an axes"

Copy link
Member

Choose a reason for hiding this comment

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

Other way around: "makes" -> "make"


>>> plt.axes()

Creating a new axes with specified dimensions and somw kwargs::
Copy link
Member

Choose a reason for hiding this comment

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

"somw" --> "some"

- 4-tuple of floats *rect* = ``[left, bottom, width, height]``.
A new axes is added with dimensions *rect* in normalized
(0, 1) units using `~.Figure.add_axes` on the current figure.
- `~.Axes`: The is is equivalent to `.pyplot.sca`. It sets the current
Copy link
Member

Choose a reason for hiding this comment

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

The is is -> This is

Copy link
Member

Choose a reason for hiding this comment

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

The order of the bullets should match the initial spec


Other Parameters
----------------
kwargs :
Copy link
Member

Choose a reason for hiding this comment

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

**kwargs

@timhoffm timhoffm force-pushed the cleanup-pyplot.axes branch from ad58045 to 5c58245 Compare December 5, 2017 21:33
@timhoffm
Copy link
Member Author

timhoffm commented Dec 5, 2017

This is related to the deprecation, as of 2.1, of accepting an existing Axes argument in Figure.add_axes. The deprecation warning can be added to the docstring here.

@efiring IMO it's a bit different. If I read correctly, the deprecation in Figure.add_axes is about the behavior when adding an identical axes no matter if it's specified as by rect and params or if it is an Axes object.

I'm speaking of deprecating Axes as a possible parameter type in pyplot.axes() right away. It's really just pyplot.sca(ax). For clarity users should just use sca then and not axes(ax).

@jklymak
Copy link
Member

jklymak commented Dec 5, 2017

If I understand correctly, that'd be a breaking change, and would at least need a deprecation period. Shouldn't hold this PR up though...

@anntzer
Copy link
Contributor

anntzer commented Dec 5, 2017

+1 to deprecation

@timhoffm
Copy link
Member Author

timhoffm commented Dec 5, 2017

I've created a separate issue #9940 for the proposed deprecation. So this can be handled separately from the above changes.

@tacaswell tacaswell modified the milestones: v2.1.1, v2.2 Dec 6, 2017
@jklymak jklymak merged commit 62c1e34 into matplotlib:master Dec 6, 2017
@jklymak
Copy link
Member

jklymak commented Dec 6, 2017

Thanks @timhoffm !

@timhoffm timhoffm deleted the cleanup-pyplot.axes branch December 6, 2017 22:41
@QuLogic QuLogic modified the milestones: needs sorting, v2.2.0 Feb 12, 2018
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.

8 participants