Skip to content

Instantly share code, notes, and snippets.

@renejahn
Created October 5, 2017 12:57
Show Gist options
  • Save renejahn/a1016590bbcf04ba19b8357222a01876 to your computer and use it in GitHub Desktop.
Save renejahn/a1016590bbcf04ba19b8357222a01876 to your computer and use it in GitHub Desktop.
close matplotlib figures via escape button
import sys
import matplotlib.pyplot as plt
def connect_close(figure=None):
def press_key(event):
if event.key == 'escape':
plt.close('all')
sys.exit(0)
if not figure:
figure = plt.gcf()
figure.canvas.mpl_connect('key_press_event', press_key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment