Skip to content

Simpler "pyplotless" use pattern. #14024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2485,19 +2485,23 @@ def key_press_handler(event, canvas=None, toolbar=None):
toggle_xscale_keys = rcParams['keymap.xscale']
all_keys = dict.__getitem__(rcParams, 'keymap.all_axes')

# toggle fullscreen mode ('f', 'ctrl + f')
if event.key in fullscreen_keys:
try:
canvas.manager.full_screen_toggle()
except AttributeError:
pass
manager = canvas.manager

# quit the figure (default key 'ctrl+w')
if event.key in quit_keys:
Gcf.destroy_fig(canvas.figure)
# quit all figures (no default)
if event.key in quit_all_keys:
Gcf.destroy_all()

if manager is not None:
# toggle fullscreen mode ('f', 'ctrl + f')
if event.key in fullscreen_keys:
canvas.manager.full_screen_toggle()
# quit the figure (default key 'ctrl+w')
if event.key in quit_keys:
if Gcf.get_fig_manager(canvas.manager.num):
Gcf.destroy_fig(canvas.figure)
else:
manager.destroy()

if toolbar is not None:
# home or reset mnemonic (default key 'h', 'home' and 'r')
if event.key in home_keys:
Expand Down Expand Up @@ -3545,15 +3549,16 @@ def draw_if_interactive(cls):
cls.trigger_manager_draw(manager)

@classmethod
def show(cls, *, block=None):
def show(cls, figures=None, *, block=None):
"""
Show all figures.
Show the *figures*, defaulting to all pyplot-managed figures.

`show` blocks by calling `mainloop` if *block* is ``True``, or if it
is ``None`` and we are neither in IPython's ``%pylab`` mode, nor in
`interactive` mode.
"""
managers = Gcf.get_all_fig_managers()
managers = ([figure.canvas.manager for figure in figures]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be more forgiving to canvases without managers?

Copy link
Contributor Author

@anntzer anntzer Nov 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think ignoring (silently or not) figures we can't show because they have no manager is really helpful?

One idea would be to auto-setup a manager for them, though.

if figures is not None else Gcf.get_all_fig_managers())
if not managers:
return
for manager in managers:
Expand Down