Python的“'模块'对象不可调用" [英] Python "'module' object is not callable"

查看:120
本文介绍了Python的“'模块'对象不可调用"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个情节:

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.

推荐答案

figurematplotlib 提供的模块.

您可以在 Matplotlib文档

我认为您想要的是 matplotlib.figure.Figure (类,而不是模块)

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

它是在此处记录的

from matplotlib import *
import sys
from pylab import *

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

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

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

或使 pylab 正常工作而不会与 matplotlib 冲突:

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

这篇关于Python的“'模块'对象不可调用"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆