问题描述
我正在尝试使用 Tkinter 创建视图,因此我也在使用 pylab.我的问题是我收到一条错误消息:
I'm trying to use Tkinter to create a view, and therefore I'm also using pylab. My problem is that I get an error saying:
AttributeError: 'module' 对象没有属性 'Figure'
错误来自这行代码:
self.fig = FigureCanvasTkAgg(pylab.figure(), master=self)
我是 python 新手,所以我不知道如何解决这个问题,因为 figure()
应该是 pylab 库的一部分.
I'm new to python, so I don't know how to fix this, since the figure()
should be a part of the pylab library.
任何有关解决此问题的建议将不胜感激.
Any suggestions on how to fix this would be appreciated.
编辑:
完整代码如下:
from Tkinter import *
import ttk
from ttk import Style
import pylab
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import matplotlib.pyplot as plt
from numpy import cumsum
import matplotlib
class GUI(Frame):
def __init__(self, parent, motspiller):
Frame.__init__(self, parent)
self.style = Style()
self.fig = None
def setup(self):
self.style.theme_use("default")
self.pack(fill=BOTH, expand=1)
label = Label(self.parent)
label.place(x=800, y=50)
quit_button = Button(self, text="Quit", command=self.quit)
quit_button.place(x=1000, y=450)
self.fig = FigureCanvasTkAgg(pylab.figure(), master=self)
self.fig.get_tk_widget().grid(column=0, row=0)
self.fig.show()
推荐答案
如果您无法运行其他任何 pylab
函数,则说明安装存在问题.我在安装 matplotlib
和 pylab
时遇到了类似的错误,结果证明安装 matplotlib
也会em> 为你安装 pylab
并且在它上面单独安装 pylab
会导致那些确切的问题.一个简单的 pip卸载pylab
为我做到了,因为它删除了新安装的 pylab
,让我导入了与 matplotlib
捆绑在一起的软件包..
If you're unable to run any of the other pylab
functions then there's a problem with your install. I just ran into a similar error when I installed matplotlib
and then pylab
, and it turns out that installing matplotlib
will also install pylab
for you and that separately installing pylab
on top of it will cause those exact problems. A simple pip uninstall pylab
did it for me, since it removed the newly installed pylab
and let me import the one that came bundled with matplotlib
instead.
这篇关于Pylab-“模块"对象没有属性“图"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!