python module_error ai_generated true

ValueError: 未知投影 '3d'

ValueError: Unknown projection '3d'

ID: python/matplotlib-3d-proj-not-registered

其他格式: JSON · Markdown 中文 · English
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.

generic

解决方案

  1. 96% 成功率
    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D  # noqa: F401
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
  2. 93% 成功率
    import matplotlib.pyplot as plt
    ax = plt.axes(projection='3d')
    ax.plot3D([0,1,2], [0,1,2], [0,1,2])

无效尝试

常见但无效的做法:

  1. 90% 失败

    mpl_toolkits ships with matplotlib; installing it separately is unnecessary and may cause version conflicts.

  2. 85% 失败

    Matplotlib projection names are case-sensitive; '3D' is not registered either.