I am attempting to use Matplotlib as a frontend for a simulator project. The simulator should take input from the user and update figures accordingly. Updating the figures in maptlotlib in real-time works fine, but there is no callbacks for events unless show() is called.
from time import sleep
import matplotlib.pyplot as plt
plt.figure()
def onclick(event):
print 'button=%d, x=%d, y=%d, xdata=%f, ydata=%f'%(
event.button, event.x, event.y, event.xdata, event.ydata)
plt.gcf().canvas.mpl_connect('button_press_event', onclick)
plt.plot([0,1,2],[5,10,15])
plt.show()
This code works and outputs events as per http://matplotlib.org/users/event_handling.html
Unfortunately I need to be able to do processing inbetween updates and cannot surrender control to show(). Changing from blocking show():
plt.show()
To non-blocking show(block=False) does not work:
plt.show(block=False)
#Running simulator, but not unable to receive events.
for i in xrange(10):
print "Working %s" %i
sleep(1)
I assume that this is related to the lack of a main loop doing event handling. I have found no information on how to do this manually.