Skip to content

Axes3d attaches itself to a figure, where as Axes does not #18364

Closed

Description

@jklymak
import matplotlib.pyplot as plt
import matplotlib.axes as maxes

fig = plt.figure()
ax = maxes.Axes(fig, [0.1, 0.1, 0.9, 0.9])
print(fig.get_children())

returns a list with no axes....

[<matplotlib.patches.Rectangle object at 0x7f8d75707dc0>]

For 3-d

import matplotlib.pyplot as plt
import matplotlib.axes as maxes
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax = Axes3D(fig)
print(fig.get_children())

has the axes attached:

[<matplotlib.patches.Rectangle object at 0x7fbc2968d160>, <mpl_toolkits.mplot3d.axes3d.Axes3D object at 0x7fbc2968df40>]

Axes3D.__init__ explicitly adds itself to its parent:

self.figure.add_axes(self)

whereas no such thing happens for the base Axes class.

Discovered as part of #18356, but discussing here because its orthogonal. But I think the behaviour here should be the same .

Activity

  1. jklymak commented on Aug 27, 2020

    @jklymak
    MemberAuthor

    Cartopy GeoAxes doesn't seem to attach itself either (consistent w/ Axes).

  2. WeatherGod commented on Aug 27, 2020

    @WeatherGod
    Member

    git blame says that line has been there for at least 10 years. This might very well be the case where we used to do this for regular 2D axes, but no longer? Also, there were a lot of oddities with the original Axes3D design 10 years ago that required an inordinate amount of hacks to get it to work. When I revamped it for v1.1.0, I trashed a lot of those hacks and simplified the conceptual model. It very well could be that I simply just missed this.

  3. WeatherGod commented on Aug 27, 2020

    @WeatherGod
    Member

    Heh, just realized that this potentially might explain an old "double-draw" bug...

  4. jklymak commented on Aug 27, 2020

    @jklymak
    MemberAuthor

    Heh, just realized that this potentially might explain an old "double-draw" bug...

    Thats exactly how I found it - I added a new double-draw bug in #18356 by storing the axes in a flat list instead of an AxesStack which gets rid of duplicates by using a key.

    I actually don't mind the idea that an axes attaches itself on instantiation - after all they require a fig as a kwarg so it makes sense. However, it would be preferable if both axes classes were consistent, and if it gets added, it should probably be added to the Axes so that all children classes also get it.

  5. dopplershift commented on Aug 27, 2020

    @dopplershift
    Contributor

    👍 to making the two consistent. I'm just not sure what the ramifications are of making Axes attach itself.

  6. jklymak commented on Aug 28, 2020

    @jklymak
    MemberAuthor

    Right now fig.add_axes(ax) only works if ax was created via Axes(fig,...), otherwise it explicitly errors out. So, is there a case where we would create an axes on a figure but not want to also add it to the axes stack?

  7. WeatherGod commented on Aug 28, 2020

    @WeatherGod
    Member
  8. jklymak commented on Aug 28, 2020

    @jklymak
    MemberAuthor

    We still technically support adding a regular Axes object to a figure
    without it being managed by a stack or whatever it was before we had the
    stack (gridspec?).

    I guess you could just add an axes as an artist w/ fig.add_artist(Axes(fig, ...))? I guess if someone wanted it out of the state-based stack (for gca etc) that would be one reason to not enforce a call to add_axes. Given that possibility I'm leaning towards just removing that call from Axes3D and making the user explicitly add all axes...

  9. anntzer commented on Mar 20, 2021

    @anntzer
    Contributor

    Closed by #19496, afaict.

  10. added this to the v3.4.0 milestone on Mar 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    API: consistencyConsistency of the matplotlib API, including naming, behavior, defaults, …topic: mplot3d

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions