For consistency with other plotting programs (such as gnuplot), I would love to have "q" as a standard key for closing a figure window.
I have a little recipe for you which does what you want.
import matplotlib.pyplot as plt plt.plot(range(10)) def quit_figure(event): if event.key == 'q': plt.close(event.canvas.figure) cid = plt.gcf().canvas.mpl_connect('key_press_event', quit_figure) plt.show()
Obviously, this doesn't give you what you asked for on all plots...
Yes, I'm already doing that for most larger scripts where it doing the work feels justified. It would just be nice to have it by default.
Fixed in #851, by default you can now close a figure with "ctrl+w" on most backends.
@pelson what did you mean by "Added a close figure key ("q" by default)" ? Where did you do the modification (inside some file?) ?
@pelson what did you mean by "Added a close figure key ("q" by default)" ?
All matplotlib figures can be closed with "ctrl + w" / "cmd + w" since a good number of years.
The changes (rather broadly) were done in #851. The specific file which changed: https://github.com/matplotlib/matplotlib/pull/851/files#diff-546df25a362e568e615b2a0558df2cbeR585
Activity
pelson commented on Apr 16, 2012
I have a little recipe for you which does what you want.
import matplotlib.pyplot as plt plt.plot(range(10)) def quit_figure(event): if event.key == 'q': plt.close(event.canvas.figure) cid = plt.gcf().canvas.mpl_connect('key_press_event', quit_figure) plt.show()Obviously, this doesn't give you what you asked for on all plots...
birkenfeld commented on Apr 16, 2012
Yes, I'm already doing that for most larger scripts where it doing the work feels justified. It would just be nice to have it by default.
pelson commented on Jul 5, 2012
Fixed in #851, by default you can now close a figure with "ctrl+w" on most backends.
hbaromega commented on Aug 8, 2015
@pelson what did you mean by "Added a close figure key ("q" by default)" ? Where did you do the modification (inside some file?) ?
pelson commented on Aug 27, 2015
All matplotlib figures can be closed with "ctrl + w" / "cmd + w" since a good number of years.
The changes (rather broadly) were done in #851. The specific file which changed: https://github.com/matplotlib/matplotlib/pull/851/files#diff-546df25a362e568e615b2a0558df2cbeR585