Skip to content

Fix Axes3D matplotlib deprecation warning in examples #22586

@lesteve

Description

@lesteve

See in #22547

MatplotlibDeprecationWarning: Axes3D(fig) adding itself to the figure is deprecated since 3.4. Pass the keyword argument auto_add_to_figure=False and use fig.add_axes(ax) to suppress this warning. The default value of auto_add_to_figure will change to False in mpl3.5 and True values will no longer work in 3.6.  This is consistent with other Axes classes

We need to replace a line like this:

ax = Axes3D(fig, elev=elev, azim=azim, rect=[0, 0, 0.95, 1])

by:

ax = fig.add_subplot(111, projection="3d", elev=elev, azim=azim)
ax.set_position([0, 0, 0.95, 1])

For matplotlib < 3.2 (matplotlib 3.1.2 is our minimum supported version of matplotlib) we need to have this import:

# unused but required import for doing 3d projections with matplotlib < 3.2
import mpl_toolkits.mplot3d  # noqa: F401

see #22594 (comment) for more details.

List of examples affected

through git grep Axes3D examples:

If you are interested to work on this issue

  • mention in a comment which file you want to work on, so that different people can work on this issue in parallel
  • open a PR changing only this file

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions