python
module_error
ai_generated
true
ValueError: Unknown projection '3d'
ID: python/matplotlib-3d-proj-not-registered
80%Fix Rate
88%Confidence
0Evidence
2024-09-19First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
Using add_subplot(projection='3d') without importing mpl_toolkits.mplot3d, so the projection is not registered.
generic中文
在未导入 mpl_toolkits.mplot3d 的情况下使用 add_subplot(projection='3d'),导致投影未注册。
Workarounds
-
96% success
import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D # noqa: F401 fig = plt.figure() ax = fig.add_subplot(111, projection='3d')
-
93% success
import matplotlib.pyplot as plt ax = plt.axes(projection='3d') ax.plot3D([0,1,2], [0,1,2], [0,1,2])
Dead Ends
Common approaches that don't work:
-
90% fail
mpl_toolkits ships with matplotlib; installing it separately is unnecessary and may cause version conflicts.
-
85% fail
Matplotlib projection names are case-sensitive; '3D' is not registered either.