2

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!

2 Answers 2

8

@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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the additional comment, you're right that I was trying to use matplotlib.pyplot() , just totally missed it. THanks
1

try

plt.figure.Figure()

not

plt.figure

1 Comment

couldn't believe I spent 2hours on this stupid mistake!! I had it right in another code....Thanks so much for point it out!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.