Permalink
Browse files

Add an event handler to quit using the escape key. By default, use 7 …

…colors (a prime number) to make identifying series easier.
  • Loading branch information...
1 parent ce93b85 commit 37e72f0f5169fa54130688c471698502d18195d7 Leif Johnson committed Jun 4, 2012
Showing with 11 additions and 3 deletions.
  1. +11 −3 scripts/py-grep-plot
View
@@ -55,7 +55,7 @@ g = optparse.OptionGroup(FLAGS, 'Series Options')
g.add_option('-a', '--alpha', type=float, default=0.9, metavar='N',
help='plot series with alpha N (0.9)')
g.add_option('-c', '--colors', default='k,r,#666666,c,b,m,g,y', metavar='S,S,...',
- help='cycle through the given colors (k,r,#666666,c,b,m,g,y)')
+ help='cycle through the given colors (k,r,c,b,m,g,y)')
g.add_option('-p', '--points', default='o-', metavar='S,S,...',
help='cycle through the given line/point styles (o-)')
FLAGS.add_option_group(g)
@@ -284,11 +284,19 @@ def main(opts, args):
logging.info('%s: saving plot', opts.output)
return pyplot.savefig(opts.output)
- quit = lambda e=None: sys.exit(0)
+ def on_close(event=None):
+ sys.exit()
+
+ def on_key(event):
+ if event.key == 'escape':
+ sys.exit()
+
try:
- pyplot.connect('close_event', quit)
+ pyplot.connect('close_event', on_close)
+ pyplot.gcf().canvas.mpl_connect('key_press_event', on_key)
except ValueError:
pass
+
try:
pyplot.show()
except KeyboardInterrupt:

0 comments on commit 37e72f0

Please sign in to comment.