fast tooth
fast tooth

Reputation: 2459

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. In plotcluster.py I have:

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

In main.py, I use 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. This makes me so confusing!

any help will be appreciated !! Thanks in advance!

Upvotes: 2

Views: 7592

Answers (2)

goofd
goofd

Reputation: 2098

@suhail 's answer will work. Essentially you were accessing matplotlib.figure which is the module. 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.

So in your plotcluster.py change the first line to

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.

Upvotes: 8

suhailvs
suhailvs

Reputation: 21680

try

plt.figure.Figure()

not

plt.figure

Upvotes: 1

Related Questions