Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A quick class for binding keys to step through an iterable in matplotlib
class push_to_advance(object):
def __init__(self):
self.fig = plt.figure()
self.ax = self.fig.gca()
self.bound_keys = []
self.bound_cid = {}
def add_step_through(self, gen, key):
key = key[0] # make a single char
if key in self.bound_keys:
raise RuntimeError("key %s already bound"%key)
first_data = gen.next()
self.ax.plot(first_data)
self.fig.canvas.draw()
self.bound_keys.append(key)
def ontype(event):
if event.key == key:
try:
self.ax.plot(gen.next())
self.fig.canvas.draw()
except StopIteration:
self.fig.canvas.mpl_disconnect(self.bound_cid[key])
del self.bound_cid[key]
self.bound_keys.remove(key)
self.bound_cid[key] = self.fig.canvas.mpl_connect('key_press_event', ontype))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.