Skip to content

gca(projection="rectilinear") fails to reset projection on axes #10700

Closed

Description

@anntzer

Bug report

Bug summary

As of 2.2:

plt.gca(projection="polar"); plt.gca(projection="lambert")

shows a warning and replaces the originally created polar axes by a lambert axes (not sure what behavior we actually want this to have once axes-collision detection in add_axes is removed).
However, in

plt.gca(projection="polar"); plt.gca(projection="rectilinear")

the second call to gca (using a rectilinear projection) fails to reset the projection at all and leaves the original polar axes in place.

Noted while thinking about #10674.

Activity

  1. efiring commented on Mar 7, 2018

    @efiring
    Member

    We need to figure out exactly what gca is supposed to do, with or without kwargs. Suggestion:

    • If the current Axes exists and matches the kwargs (if any), return it.
    • If the current Axes exists and doesn't match the request, raise an Exception.
    • Otherwise, make a new Axes as requested.

    Note: All this is in the pyplot context, where there can be many Axes, Figures, and Images, but for each of these categories there is a single current one.

    In my suggestion, gca would not search through existing Axes--it would only check to see if it can use the current one. It would never modify or delete the current Axes.

    I think that part of the problem we are running into is confusion between gca as a user-level pyplot command, and our use of gca inside pyplot functions, like polar. Functions like gca and polar should be simple--they were supposed to be designed for casual users and quick use. We need to lay out the simple scenarios for their use, and construct and document them accordingly.

    If such a scenario includes gca(); polar(r, theta); then the logic for replacing the current rectilinear Axes with a polar Axes can reside in polar, without complicating gca.

  2. efiring commented on Mar 7, 2018

    @efiring
    Member

    Addendum: Looking at some code, I suspect my precise suggestion is not feasible (can't get there from here), but the basic points remain.

  3. timhoffm commented on Apr 4, 2018

    @timhoffm
    Member

    I agree with @efiring's suggestion. In my interpretation, the main purpose is "getting the current axes" as the name says - no arguments required. As a fallback, if no axes exists, one is created which may need the parameters "get the current axes with these parameters".

    For a sane API plt.gca(projection="rectilinear") must always result in a rectilinear axes and not change the current axes. Otherwise it should fail with an exception.

    If a function like polar needs a certain projection it has to care for that itself.

    Why exactly do you think a clean gca is not feasible?

  4. anntzer commented on Apr 4, 2018

    @anntzer
    ContributorAuthor

    (fwiw I don't actually really care about what the exact semantics of gca() are (I don't ever use it, after all :-)), other that they should be reasonably consistent... additional points if it allows us to get rid of (parts of) the internal AxesStack object, which seems to try to do too much IMO)

  5. anntzer commented on Dec 24, 2019

    @anntzer
    ContributorAuthor

    Looking at this again I wonder whether the simple solution is not just to deprecate all kwargs to gca() (one can instead call plt.subplot(**kwargs) to create a new subplot) and restrict gca() to, well, returning the current axes and do nothing else.

  6. timhoffm commented on Dec 25, 2019

    @timhoffm
    Member

    Agreed, that plt.gca() should not be used to create complex axes, so kwargs should be deprecated.

    I would still allow a bare plt.gca() to create a default figure/axes if none exists. That's in the spirit of pyplot: A figure and axes are automatically created if necessary.

  7. anntzer commented on Dec 25, 2019

    @anntzer
    ContributorAuthor

    Yes, gca() should still create an axes if none exists.

  8. added 5 commits that reference this issue on Feb 12, 2021
    8f8cf4e
    14c8394
    337dc38
    e1987ce
    d854e5a
  9. added a commit that references this issue on Mar 8, 2021
    c30b5a7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions