Skip to content

Try/except import of Axes3D #27178

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 3 commits into from
Oct 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions lib/matplotlib/projections/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,15 @@
from .. import axes, _docstring
from .geo import AitoffAxes, HammerAxes, LambertAxes, MollweideAxes
from .polar import PolarAxes
from mpl_toolkits.mplot3d import Axes3D

try:
from mpl_toolkits.mplot3d import Axes3D
except ImportError:
import warnings
warnings.warn("Unable to import Axes3D. This may be due to multiple versions of "
"Matplotlib being installed (e.g. as a system package and as a pip "
"package). As a result, the 3D projection is not available.")
Axes3D = None


class ProjectionRegistry:
Expand Down Expand Up @@ -87,8 +95,12 @@ def get_projection_names(self):
HammerAxes,
LambertAxes,
MollweideAxes,
Axes3D,
)
if Axes3D is not None:
projection_registry.register(Axes3D)
else:
# remove from namespace if not importable
del Axes3D


def register_projection(cls):
Expand Down