python
module_error
ai_generated
true
ValueError: 未知投影'3d'
ValueError: Unknown projection '3d'
ID: python/matplotlib-3d-projection-error
80%修复率
88%置信度
0证据数
2024-02-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.7 | active | — | — | — |
| 3.8 | active | — | — | — |
根因分析
尝试创建3D子图,但未导入mpl_toolkits.mplot3d,或使用了不支持'3d'投影的旧版matplotlib。
English
Trying to create a 3D subplot without importing mpl_toolkits.mplot3d or using an older matplotlib version where '3d' is not recognized.
解决方案
-
95% 成功率 Import mpl_toolkits.mplot3d explicitly
from mpl_toolkits.mplot3d import Axes3D; fig = plt.figure(); ax = fig.add_subplot(111, projection='3d')
-
90% 成功率 Use the built-in subplot_kw argument
fig, ax = plt.subplots(subplot_kw={'projection': '3d'})
无效尝试
常见但无效的做法:
-
Installing mpl_toolkits via pip
95% 失败
mpl_toolkits is part of matplotlib, not a separate package.
-
Using projection='3d' without importing anything
90% 失败
The projection is registered only after importing mpl_toolkits.mplot3d.