尽管调用 help(gridspec) 揭示了 Gridspec 类,但“'module'对象没有属性'Gridspec'”

Olh*_*sky -1 python matplotlib

如果我运行 python 控制台并执行

import matplotlib
matplotlib.__version__
import matplotlib.gridspec as gs
Run Code Online (Sandbox Code Playgroud)

我看到matplotlib版本是1.2.1。

如果我这样做,help(gs)我会看到 Gridspec 类。

然而下面的代码

import matplotlib
import matplotlib.gridspec as gs
g = gs.Gridspec(1,1)
Run Code Online (Sandbox Code Playgroud)

产生错误:

AttributeError: 'module' object has no attribute 'Gridspec'

为什么我无法创建新的 Gridspec 对象?

Mat*_*ams 5

你本来想打字g = gs.GridSpec(1,1)。“Spec”中的“s”大写。

  • 我一生中最糟糕的一个小时的使用。感谢您的解决方案。当你累的时候不要编程。 (3认同)