# ValueError: 未知投影'3d'

- **ID:** `python/matplotlib-3d-projection-error`
- **领域:** python
- **类别:** module_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

尝试创建3D子图，但未导入mpl_toolkits.mplot3d，或使用了不支持'3d'投影的旧版matplotlib。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.7 | active | — | — |
| 3.8 | active | — | — |

## 解决方案

1. **Import mpl_toolkits.mplot3d explicitly** (95% 成功率)
   ```
   from mpl_toolkits.mplot3d import Axes3D; fig = plt.figure(); ax = fig.add_subplot(111, projection='3d')
   ```
2. **Use the built-in subplot_kw argument** (90% 成功率)
   ```
   fig, ax = plt.subplots(subplot_kw={'projection': '3d'})
   ```

## 无效尝试

- **Installing mpl_toolkits via pip** — mpl_toolkits is part of matplotlib, not a separate package. (95% 失败率)
- **Using projection='3d' without importing anything** — The projection is registered only after importing mpl_toolkits.mplot3d. (90% 失败率)
