简体   繁体   English

Python模块不可调用

[英]Python module not callable

I searched many posts, but they don't seem to be helpful. 我搜索了很多帖子,但它们似乎没有帮助。

In folder dir1/ I have main.py and plotcluster.py. 在文件夹dir1 /中,我有main.py和plotcluster.py。 In plotcluster.py I have: 在plotcluster.py中,我有:

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

In main.py, I use plotcluster.py: 在main.py中,我使用plotcluster.py:

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

But this gives me a error saying module object is not callable. 但这给我一个错误,指出模块对象不可调用。

     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

It doesn't complaint about the itertools module, but the plt one bothers it. 它没有抱怨itertools模块,但是请麻烦它。 This makes me so confusing! 这让我感到困惑!

any help will be appreciated !! 任何帮助将不胜感激 !! Thanks in advance! 提前致谢!

@suhail 's answer will work. @suhail的答案将起作用。 Essentially you were accessing matplotlib.figure which is the module. 本质上,您正在访问模块的matplotlib.figure。 Also I think you are trying to access the pyplot functions (gen that is imported as plt) and its enough to import that module to access most of the standard plotting api's. 我也认为您正在尝试访问pyplot函数(作为plt导入的gen)及其足以导入该模块以访问大多数标准绘图api的函数。

So in your plotcluster.py change the first line to 因此,在您的plotcluster.py将第一行更改为

import matplotlib.pyplot as plt

It should be smooth sailing from there on and you can use stuff like 从那里开始应该平稳航行,您可以使用类似

plt.plot() , plt.show() and so on. plt.plot()plt.show()等。

try 尝试

plt.figure.Figure()

not

plt.figure

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM