python
module_error
ai_generated
true
ValueError: Unknown projection '3d'
ID: python/matplotlib-3d-projection-error
80%Fix Rate
88%Confidence
0Evidence
2024-02-20First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.7 | active | — | — | — |
| 3.8 | active | — | — | — |
Root Cause
Trying to create a 3D subplot without importing mpl_toolkits.mplot3d or using an older matplotlib version where '3d' is not recognized.
generic中文
尝试创建3D子图,但未导入mpl_toolkits.mplot3d,或使用了不支持'3d'投影的旧版matplotlib。
Workarounds
-
95% success Import mpl_toolkits.mplot3d explicitly
from mpl_toolkits.mplot3d import Axes3D; fig = plt.figure(); ax = fig.add_subplot(111, projection='3d')
-
90% success Use the built-in subplot_kw argument
fig, ax = plt.subplots(subplot_kw={'projection': '3d'})
Dead Ends
Common approaches that don't work:
-
Installing mpl_toolkits via pip
95% fail
mpl_toolkits is part of matplotlib, not a separate package.
-
Using projection='3d' without importing anything
90% fail
The projection is registered only after importing mpl_toolkits.mplot3d.