Skip to content

Warn re: Axes3D constructor behavior change in mpl3.4 #18939

Closed

Description

@larsoner

According to git bisect, 261f706 by @anntzer broke the following code, adapted from the examples -- it produces a blank / empty plot:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = Axes3D(fig)
# ax = fig.gca(projection='3d')
X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)
surf = ax.plot_surface(X, Y, Z)

If you comment out the ax = Axes3D(fig) line and use ax = fig.gca(projection='3d'), it works fine. It also works fine on the preceding commit 34f99a9.

Activity

  1. anntzer commented on Nov 12, 2020

    @anntzer
    Contributor

    That was actually mostly discussed in #18356. The change was definitely intentional (as both #18356 and #18564 needed it) and documented at https://github.com/matplotlib/matplotlib/blob/master/doc/api/next_api_changes/behavior/18564-AL.rst; do you want to discuss reverting it, or emit a warning, or something else?

  2. larsoner commented on Nov 12, 2020

    @larsoner
    ContributorAuthor

    Ahh I just didn't notice that change. A warning that it is no longer added would have made finding the problem immediately apparent, so +1 for that solution if it's tractable.

  3. added this to the v3.4.0 milestone on Nov 12, 2020
  4. anntzer commented on Nov 12, 2020

    @anntzer
    Contributor

    I think we can (temporarily) add a warning in Axes3D.__del__ checking whether the axes has ever been added to a figure.

  5. changed the title [-]BUG: Regression in Axes3D use[/-] [+]Warn re: Axes3D constructor behavior change in mpl3.4[/+] on Nov 12, 2020
  6. larsoner commented on Nov 12, 2020

    @larsoner
    ContributorAuthor

    Actually a simpler approach would be just to add a add=True argument to Axes3D. Then people who used it like I did get their behavior preserved, and internally matplotlib can do add=False. Then there isn't any need for the release notes or user changes. And hopefully it's just two lines if add: fig.add_subplot(self) or so.

  7. added
    Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
    on Feb 1, 2021
  8. added 2 commits that reference this issue on Feb 17, 2021
    f1938e8
    668cecc
  9. added a commit that references this issue on Mar 8, 2021
    505e9bf
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

    Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.topic: mplot3d

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions