Python & ldquo; the 'module' object can not be called & rdquo;

advertisements

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.


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) )