From 6cface1636fbfeb47747ea2cef33fba8559c7d72 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 17 May 2023 14:31:10 +0200 Subject: [PATCH 1/3] fix canvas.draw() in callback --- mne/viz/topomap.py | 5 +++-- mne/viz/utils.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mne/viz/topomap.py b/mne/viz/topomap.py index 4641014b96e..76a142fb3d0 100644 --- a/mne/viz/topomap.py +++ b/mne/viz/topomap.py @@ -1647,7 +1647,7 @@ def plot_ica_components( fig.canvas.draw() # add title selection interactivity - def onclick_title(event, ica=ica, titles=subplot_titles): + def onclick_title(event, ica=ica, titles=subplot_titles, fig=fig): # check if any title was pressed title_pressed = None for title in titles: @@ -1705,7 +1705,8 @@ def onclick_topo(event, ica=ica, inst=inst): fig.canvas.mpl_connect("button_press_event", onclick_topo) figs.append(fig) - plt_show(show) + for fig in figs: + plt_show(show, fig) return figs[0] if len(figs) == 1 else figs diff --git a/mne/viz/utils.py b/mne/viz/utils.py index bdf51d8202d..f220750fe3c 100644 --- a/mne/viz/utils.py +++ b/mne/viz/utils.py @@ -141,11 +141,12 @@ def plt_show(show=True, fig=None, **kwargs): Extra arguments for :func:`matplotlib.pyplot.show`. """ import matplotlib.pyplot as plt - from matplotlib import get_backend if hasattr(fig, "mne") and hasattr(fig.mne, "backend"): backend = fig.mne.backend else: + from matplotlib import get_backend + backend = get_backend() if show and backend != "agg": (fig or plt).show(**kwargs) From a37cc39660bba3a566b8e1552edfdc3981eb62a8 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 17 May 2023 14:36:24 +0200 Subject: [PATCH 2/3] revert --- mne/viz/utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mne/viz/utils.py b/mne/viz/utils.py index f220750fe3c..bdf51d8202d 100644 --- a/mne/viz/utils.py +++ b/mne/viz/utils.py @@ -141,12 +141,11 @@ def plt_show(show=True, fig=None, **kwargs): Extra arguments for :func:`matplotlib.pyplot.show`. """ import matplotlib.pyplot as plt + from matplotlib import get_backend if hasattr(fig, "mne") and hasattr(fig.mne, "backend"): backend = fig.mne.backend else: - from matplotlib import get_backend - backend = get_backend() if show and backend != "agg": (fig or plt).show(**kwargs) From 1a725143666b6e08f7ce656eb07fceeea0e12f03 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 17 May 2023 14:37:44 +0200 Subject: [PATCH 3/3] revert test --- mne/viz/topomap.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mne/viz/topomap.py b/mne/viz/topomap.py index 76a142fb3d0..df6c16f622b 100644 --- a/mne/viz/topomap.py +++ b/mne/viz/topomap.py @@ -1705,8 +1705,7 @@ def onclick_topo(event, ica=ica, inst=inst): fig.canvas.mpl_connect("button_press_event", onclick_topo) figs.append(fig) - for fig in figs: - plt_show(show, fig) + plt_show(show) return figs[0] if len(figs) == 1 else figs