Python 属性错误:';模块';对象没有属性

Python 属性错误:';模块';对象没有属性,python,python-2.7,Python,Python 2.7,我看过其他关于这个话题的帖子,并没有找到一个明确的答案,尽管我相信这很简单 我的代码具有以下结构 import matplotlib ... ... class xyz: def function_A(self,...) ... ... fig1 = matplotlib.figure() ... ... 我正在从“xyz”的实例调用“function_A”,当我调用时,会收到错误消息: Attribut

我看过其他关于这个话题的帖子,并没有找到一个明确的答案,尽管我相信这很简单

我的代码具有以下结构

import matplotlib
...
...

class xyz:
    def function_A(self,...)
        ...
        ...
        fig1 = matplotlib.figure()
        ...
        ...
我正在从“xyz”的实例调用“function_A”,当我调用时,会收到错误消息:

AttributeError: 'module' object has no attribute 'figure'
根据我读到的帖子,我导入matplotlib的方式似乎有问题,但我无法解决。我曾尝试在函数定义中导入它(我认为这是一种糟糕的形式,但我想测试它),但我仍然犯了同样的错误

我在其他地方使用了“function_A”代码,没有问题,但它只是模块中的函数,而不是类中的方法


感谢您的帮助

我认为你是对的,这是一个重要的问题。
matplotlib
模块没有
figure
功能:

>>> import matplotlib
>>> matplotlib.figure
Traceback (most recent call last):
  File "<ipython-input-130-82eb15b3daba>", line 1, in <module>
    matplotlib.figure
AttributeError: 'module' object has no attribute 'figure'
导入matplotlib >>>matplotlib.figure 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 matplotlib.figure AttributeError:“module”对象没有属性“figure” figure函数位于更深的位置。有几种方法可以将其引入,但通常的导入看起来更像:

>>> import matplotlib.pyplot as plt
>>> plt.figure
<function figure at 0xb2041ec>
>>将matplotlib.pyplot作为plt导入
>>>plt.图

坚持这种习惯可能是一个好主意,因为您在Web上找到的大多数示例都使用这种习惯,例如。(当我需要弄清楚如何做某事时,画廊仍然是我第一个去的地方:我找到一张看起来像我想要的图片,然后看看代码。)

天哪,我是个白痴。我的其他代码正确地导入了模块。谢谢你的帮助。