Nickpick
Nickpick

Reputation: 6587

MatPlotLib on Tkinter finished with exit code -1073741819 in Python 3

The following code works well in Python 2.7, but gives an error message in Python 3.3 (finished with exit code -1073741819). The error seems to occur in canvas = FigureCanvasTkAgg(self.f, master=self.root) - debugging does not show any additional information. Any suggestions what could be the cause and how to fix it are appreciated.

The original code originates from the below link, which describes how to integrate matplotlib with tkinter: http://matplotlib.org/examples/user_interfaces/embedding_in_tk.html

import tkinter as tk
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.figure import Figure
import Charts as sp
class GUI(tk.Frame):
    def __init__(self, master=None):
        self.l=[]
        self.active=False
        self.root = self.root = tk.Tk()
        self.root.title('Test')

        self.x=[]; self.y=[]; self.x = range(0, 100)
        for each in self.x:
            self.y.append(2)
        self.f = Figure(figsize=(5,4), dpi=60);
        self.a = self.f.add_subplot(111)

        self.line1, = self.a.plot(self.x, self.y, 'r-') # Returns a tuple of line objects, thus the comma
        self.a.axis((0,100,0,5))
        self.a.set_title('Plot Title')
        canvas = FigureCanvasTkAgg(self.f, master=self.root)
        canvas.show()

if __name__ == '__main__':
    gui = GUI()
    gui.root.mainloop()

Upvotes: 1

Views: 769

Answers (2)

user6023430
user6023430

Reputation: 65

I ran into the same issue. Update matplotlib in Anaconda solved the issue. In ipython, you can type
!conda update matplotlib to do the update.

Upvotes: 0

Nickpick
Nickpick

Reputation: 6587

The problem was with Anaconda. Removing and reinstalling Matplotlib resolved the problem.

Upvotes: 2

Related Questions