python
module_error
ai_generated
true
ValueError: 未知投影 '3d'
ValueError: Unknown projection '3d'
ID: python/matplotlib-3d-proj-not-registered
80%修复率
88%置信度
0证据数
2024-09-19首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
在未导入 mpl_toolkits.mplot3d 的情况下使用 add_subplot(projection='3d'),导致投影未注册。
English
Using add_subplot(projection='3d') without importing mpl_toolkits.mplot3d, so the projection is not registered.
解决方案
-
96% 成功率
import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D # noqa: F401 fig = plt.figure() ax = fig.add_subplot(111, projection='3d')
-
93% 成功率
import matplotlib.pyplot as plt ax = plt.axes(projection='3d') ax.plot3D([0,1,2], [0,1,2], [0,1,2])
无效尝试
常见但无效的做法:
-
90% 失败
mpl_toolkits ships with matplotlib; installing it separately is unnecessary and may cause version conflicts.
-
85% 失败
Matplotlib projection names are case-sensitive; '3D' is not registered either.