Reputation: 3484
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.
Upvotes: 7
Views: 72367
Reputation: 1
Wrong Library:
import matplotlib as plt
plt.figure(figsize=(7, 7))
TypeError: 'module' object is not callable
But
Correct Library:
import matplotlib.pyplot as plt
plt.figure(figsize=(7, 7))
Above code worked for me for the same error.
Upvotes: 0
Reputation: 11
For Jupyter notebook I solved this issue by importig matplotlib.pyplot instead.
import matplotlib.pyplot as plt
%matplotlib notebook
Making plots with f = plt.figure()
now works.
Upvotes: 0
Reputation: 3093
Instead of
from matplotlib import *
use
import matplotlib.pyplot as plt
Upvotes: 3
Reputation: 33
To prevent future errors regarding matplotlib.pyplot, try doing this: import matplotlib.pyplot as plt
If you use Jupyter notebooks and use: %matplotlib inline, make sure that the "%matplotlib inline FOLLOWS the import matplotlib.pyplot as plt
Karthikr's answer works but might not eliminate errors in other lines of code related to the pyplot module.
Happy coding!!
Upvotes: 2
Reputation: 99630
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))
Upvotes: 3
Reputation: 15058
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) )
Upvotes: 13