Python模块不可调用

时间:2013-06-28 03:36:37

标签: python module

我搜索了很多帖子,但似乎没有帮助。

在文件夹dir1 /我有main.py和plotcluster.py。在plotcluster.py我有:

import matplotlib as plt
import itertools as it
....
def plotc():
    colors = it.cycle('ybmgk')
    ....
    plt.figure()
    ....

在main.py中,我使用plotcluster.py:

import plotcluster as plc
....
plc.plotc()

但是这给我一个错误,说模块对象不可调用。

     20     linestyles = it.cycle('-:_')
     21
---> 22     plt.figure()
     23     # plot the most frequent ones first
     24     for iter_count, (i, _) in enumerate(Counter(centerid).most_common()):

TypeError: 'module' object is not callable

它不会抱怨itertools模块,但是它会让人烦恼。这让我很困惑!

任何帮助将不胜感激!提前谢谢!

2 个答案:

答案 0 :(得分:6)

@suhail的回答将起作用。基本上你是访问matplotlib.figure这是模块。此外,我认为您正在尝试访问pyplot函数(导入为plt的gen),并且足以导入该模块以访问大多数标准绘图API。

所以在plotcluster.py中将第一行更改为

import matplotlib.pyplot as plt

从那里开始应该是顺畅的,你可以使用像

这样的东西

plt.plot()plt.show()等等。

答案 1 :(得分:1)

plt.figure.Figure()

不是

plt.figure