Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pylab - 'module' object has no attribute 'Figure'

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' object has no attribute 'Figure'

and the error comes from this line of code:

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

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.

EDIT:

Here's the full code:

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()
like image 251
martin Avatar asked Aug 28 '15 21:08

martin


1 Answers

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.

like image 84
sevko Avatar answered Sep 24 '22 06:09

sevko