python - Pylab - 'module' 对象没有属性 'Figure'

标签 python matplotlib tkinter

我正在尝试使用 Tkinter 创建 View ,因此我也在使用 pylab。我的问题是我收到一条错误消息:

AttributeError: 'module' object has no attribute 'Figure'

错误来自这行代码:

self.fig = FigureCanvasTkAgg(pylab.figure(), master=self)

我是 python 的新手,所以我不知道如何解决这个问题,因为 figure() 应该是 pylab 库的一部分。

如有任何关于如何解决此问题的建议,我们将不胜感激。

编辑:

完整代码如下:

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 也会 为你安装 pylab 并且在它上面单独安装 pylab 会导致那些确切的问题。一个简单的 pip uninstall pylab 就帮我做了,因为它删除了新安装的 pylab 并让我导入与 matplotlib 捆绑在一起的那个.

关于python - Pylab - 'module' 对象没有属性 'Figure',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32279887/

相关文章:

pandas - 将索引转换为名称 pandas 以进行绘图

python - 更改 tkinter 菜单的字体

python - 快速 Tkinter 格式化问题

python - 使用 numpy.loadtxt 加载复数

python - 是否可以控制函数在 python 中的执行方式?

python - 从文本文件中检索 JSON 对象(使用 Python)

python - 使用 matplotlib 的 3D 曲面图,使用数据框列输入数据

python - 只有终端的 ubuntu 服务器上的 Pygame 错误 "Video system not initialized"

类似于 MATLAB 中的 Python 交互式选择工具

python - 导入 tkinter 重复打印输出