Python“'模块'对象不可调用”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16527149/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python "'module' object is not callable"
提问by rferdinand
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.
我之前运行过一个类似的脚本,我想我已经导入了所有相关的模块。
采纳答案by Ewan
The figureis a module provided by matplotlib.
的figure是所提供的模块matplotlib。
You can read more about it in the Matplotlib documentation
您可以在Matplotlib 文档中阅读更多相关信息
I think what you want is matplotlib.figure.Figure(the class, rather than the module)
我认为你想要的是matplotlib.figure.Figure(类,而不是模块)
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 pylabto work without conflicting with matplotlib:
或在pylab不与matplotlib以下冲突的情况下开始工作:
from matplotlib import *
import sys
import pylab as pl
f = pl.figure( figsize =(7,7) )
回答by karthikr
回答by minion_1
To prevent future errors regarding matplotlib.pyplot, try doing this: import matplotlib.pyplot as plt
为了防止将来出现关于 matplotlib.pyplot 的错误,请尝试这样做: 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
如果您使用 Jupyter notebooks 并使用:%matplotlib inline,请确保“%matplotlib inline FOLLOWS import matplotlib.pyplot as plt
Karthikr's answer works but might not eliminate errors in other lines of code related to the pyplot module.
Karthikr 的答案有效,但可能无法消除与 pyplot 模块相关的其他代码行中的错误。
Happy coding!!
快乐编码!!
回答by Pirate X
Instead of
代替
from matplotlib import *
use
用
import matplotlib.pyplot as plt

