Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python "'module' object is not callable"

I'm trying to make a plot:

from matplotlib import *
import sys
from pylab import *

f = figure ( figsize =(7,7) )

But I get this error when I try to execute it:

  File "mratio.py", line 24, in <module>
    f = figure( figsize=(7,7) )
TypeError: 'module' object is not callable

I have run a similar script before, and I think I've imported all the relevant modules.

like image 712
ylangylang Avatar asked May 13 '13 16:05

ylangylang


2 Answers

The figure is a module provided by matplotlib.

You can read more about it in the Matplotlib documentation

I think what you want is matplotlib.figure.Figure (the class, rather than the module)

It's documented here

from matplotlib import *
import sys
from pylab import *

f = figure.Figure( figsize =(7,7) )

or

from matplotlib import figure
f = figure.Figure( figsize =(7,7) )

or

from matplotlib.figure import Figure
f = Figure( figsize =(7,7) )

or to get pylab to work without conflicting with matplotlib:

from matplotlib import *
import sys
import pylab as pl

f = pl.figure( figsize =(7,7) )
like image 187
Ewan Avatar answered Nov 10 '22 06:11

Ewan


You need to do:

matplotlib.figure.Figure

Here,

matplotlib.figure is a package (module), and `Figure` is the method

Reference here.

So you would have to call it like this:

f = figure.Figure(figsize=(7,7))
like image 34
karthikr Avatar answered Nov 10 '22 06:11

karthikr