Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 90dfb0b

Browse files
committed
Try/except import of Axes3D
On some installs, the `mpl_toolkits` namespace package gets an old version which uses deprecated (And removed) code from the main library. On such the import of Axes3D will error with an `ImportError`. This prevents users from using any of `matplotlib`, since it is imported unconditionally by default. This just try/excepts the imports (and adjusts the registration code accordingly) to allow users to continue using matplotlib (though not 3D and possibly not other mpl_toolkits) even with older installs occluding the mpl_toolkits.
1 parent fcd5bb1 commit 90dfb0b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/matplotlib/projections/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@
5555
from .. import axes, _docstring
5656
from .geo import AitoffAxes, HammerAxes, LambertAxes, MollweideAxes
5757
from .polar import PolarAxes
58-
from mpl_toolkits.mplot3d import Axes3D
58+
59+
try:
60+
from mpl_toolkits.mplot3d import Axes3D
61+
except ImportError:
62+
Axes3D = None
5963

6064

6165
class ProjectionRegistry:
@@ -87,8 +91,12 @@ def get_projection_names(self):
8791
HammerAxes,
8892
LambertAxes,
8993
MollweideAxes,
90-
Axes3D,
9194
)
95+
if Axes3D is not None:
96+
projection_registry.register(Axes3D)
97+
else:
98+
# remove from namespace if not importable
99+
del Axes3D
92100

93101

94102
def register_projection(cls):

0 commit comments

Comments
 (0)