I am running a simple tkinter application that plots some data with an animated graph. When using matplotlib.figure.Figure and add_subplot, when I close the window with the upper-menu 'X' button (windows default) the program terminates well. Working code:
self.f = matplotlib.figure.Figure(figsize=(6, 4), dpi=100)
self.ax = self.f.add_subplot(111)
Now, when I try to use matplotlib.pyplot.figure together with matplotlib.pyplot.subplot2grid, then the 'X' does close the window but the program keeps running.
self.f = plt.figure(figsize=(6, 4), dpi=100)
self.ax = plt.subplot2grid((6,4), (0,0), rowspan=6, colspan=4)
I've tried adding matplotlib.pyplot.close("all") at the end of the program but the app doesn't exit the mainloop at all:
app = myApp()
app.mainloop() # doesn't exit
plt.close("all") # doesn't get executed
Any possible reason and alternatives?
PS: Using self.protocol("WM_DELETE_WINDOW", self.destroy) doesn't work (where self is the tk.TK instance).
pyplotin a GUI application like tkinter can lead to problems due to the GUI mainloop and the pyplot state machine both trying to manage the same objects. I would recommend not using pyplot at all when embedding matplotlib in GUIs; this allows to circumvent such problems from the start.