Hi, I'm new to matplotlib, trying to migrate from Matlab, so please excuse my rookie ignorance and Matlab thinking.
My question is: why does a GUI figure crash upon repeated calls in IPython?
Here is a detailed description:
I'm using the Enthought Python Distribution (EPD_Py25) and I enter IPython with the command: "ipython". I then run the script below using: %run myScript.py. Everything works fine: when I press 'Enter' while in the GUI the figure closes and I can retrieve the data from obj.x. However, when I run the script again using %run myScript.py a figure is generated but nothing happens; I am forced to reset everything using pyplot.close('all'), but cannot regain the GUI functionality without exiting IPython.
This problem does not occur if I use EPD's PyLab (i.e. "ipython -pylab"). Does anyone know why?
Here is the script:
from numpy.random import rand
from matplotlib import pyplot
class myGUI:
def __init__(self,x):
self.fig = pyplot.gcf()
self.x = x
#initiate figure:
self.connect()
pyplot.plot(self.x)
pyplot.show()
def connect(self):
self.cidkeypress = self.fig.canvas.mpl_connect('key_press_event', self.keypress)
def disconnect(self):
self.fig.canvas.mpl_disconnect(self.cidkeypress)
pyplot.close(self.fig)
def keypress(self,event):
if event.key == 'enter':
self.disconnect()
else:
self.x = rand(self.x.size)
pyplot.plot(self.x)
self.fig.canvas.draw()
pyplot.figure()
obj = myGUI(rand(10))