【问题标题】:ValueError: Unknown projection '3d' (once again)ValueError:未知投影“3d”(再次)
【发布时间】:2019-10-06 21:38:49
【问题描述】:

执行这行代码时:

import matplotlib.pyplot as plt

#your code

fig = plt.figure()
ax = fig.gca(projection='3d')

我有一个输出错误:

raise ValueError("Unknown projection %r" % projection)

ValueError: Unknown projection '3d'

<Figure size 432x288 with 0 Axes>

当我使用 Spyder 作为 IDE 时也会出现该错误。 matplotlib的版本是

print('matplotlib: {}'.format(matplotlib.__version__))
matplotlib: 1.5.0rc3

但即使使用其他版本的matplotlib,我也遇到了同样的问题。 this question (Stackoverflow) 中报告了类似的错误,但答案无济于事。关于如何修改指令的一些建议? matplotlib:3.0.2

【问题讨论】:

    标签: python matplotlib 3d conda spyder


    【解决方案1】:

    您必须导入 Axes3D 才能在 matplotlib 中启用 3d 绘图。 3d绘图的官方教程可以找到here。所以正确的导入和代码看起来像

    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D # <--- This is important for 3d plotting 
    
    #your code
    
    fig = plt.figure()
    ax = fig.gca(projection='3d')
    

    【讨论】:

      猜你喜欢
      • 2011-04-18
      • 2015-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-03
      • 2021-01-04
      • 2011-06-03
      相关资源
      最近更新 更多