Skip to content

Loading…

standard key for closing figure ("q") #830

Closed
birkenfeld opened this Issue · 5 comments

3 participants

@birkenfeld

For consistency with other plotting programs (such as gnuplot), I would love to have "q" as a standard key for closing a figure window.

@pelson
Matplotlib Developers member

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

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
Matplotlib Developers member

Fixed in #851, by default you can now close a figure with "ctrl+w" on most backends.

@pelson pelson closed this
@hbaromega

@pelson what did you mean by "Added a close figure key ("q" by default)" ? Where did you do the modification (inside some file?) ?

@pelson
Matplotlib Developers member

@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

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.