Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions doc/changes/dev/13606.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug where :func:`mne.viz.plot_raw` would access incorrect matplotlib attributes, by :newcontrib:`Thomas Caswell`.
1 change: 1 addition & 0 deletions doc/changes/names.inc
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@
.. _Teon Brooks: https://github.com/teonbrooks
.. _Tharupahan Jayawardana: https://github.com/tharu-jwd
.. _Thomas Binns: https://github.com/tsbinns
.. _Thomas Caswell: https://tacaswell.github.io
Copy link
Member

Choose a reason for hiding this comment

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

... and add a changelog entry for you, pulled this URL from your GitHub profile hopefully it's good enough!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you!

Sorry for not following your contribution guidelines. We debugged this from the traceback you posted on the mpl issue during our weekly dev call and I squeezed in getting this PR open between the next set of meetings, some other work, and dinnertime!

Copy link
Member

Choose a reason for hiding this comment

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

No problem, happy to push a quick commit to get this over the finish line! You did the hard work of debugging, much appreciated

.. _Thomas Hartmann: https://github.com/thht
.. _Thomas Radman: https://github.com/tradman
.. _Théodore Papadopoulo: https://github.com/papadop
Expand Down
12 changes: 3 additions & 9 deletions mne/viz/tests/test_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,16 +318,13 @@ def test_scale_bar(browser_backend):
assert_allclose(y_lims, bar_lims, atol=1e-4)


def test_plot_raw_selection(raw, browser_backend, monkeypatch):
def test_plot_raw_selection(raw, browser_backend):
"""Test selection mode of plot_raw()."""
ismpl = browser_backend.name == "matplotlib"
with raw.info._unlock():
raw.info["lowpass"] = 10.0 # allow heavy decim during plotting
browser_backend._close_all() # ensure all are closed
assert browser_backend._get_n_figs() == 0
# https://github.com/matplotlib/matplotlib/issues/30575
monkeypatch.setattr(mne.viz.utils, "_BLIT_KWARGS", dict(useblit=False))
monkeypatch.setattr(mne.viz._mpl_figure, "_BLIT_KWARGS", dict(useblit=False))
Comment on lines -328 to -330
Copy link
Member

Choose a reason for hiding this comment

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

@tacaswell I pushed a commit to remove the workaround...

fig = raw.plot(group_by="selection", proj=False)
assert browser_backend._get_n_figs() == 2
sel_fig = fig.mne.fig_selection
Expand Down Expand Up @@ -496,13 +493,10 @@ def test_plot_raw_child_figures(raw, browser_backend):
fig._resize_by_factor(0.5)


def test_orphaned_annot_fig(raw, browser_backend, monkeypatch):
def test_orphaned_annot_fig(raw, browser_backend):
"""Test that annotation window is not orphaned (GH #10454)."""
if browser_backend.name != "matplotlib":
return
# https://github.com/matplotlib/matplotlib/issues/30575
monkeypatch.setattr(mne.viz.utils, "_BLIT_KWARGS", dict(useblit=False))
monkeypatch.setattr(mne.viz._mpl_figure, "_BLIT_KWARGS", dict(useblit=False))
assert browser_backend._get_n_figs() == 0
fig = raw.plot()
_spawn_child_fig(fig, "fig_annotation", browser_backend, "a")
Expand All @@ -527,7 +521,7 @@ def _norm():
fig.showNormal = _norm


def test_plot_raw_keypresses(raw, browser_backend, monkeypatch):
def test_plot_raw_keypresses(raw, browser_backend):
"""Test keypress interactivity of plot_raw()."""
with raw.info._unlock():
raw.info["lowpass"] = 10.0 # allow heavy decim during plotting
Expand Down
15 changes: 7 additions & 8 deletions mne/viz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1656,7 +1656,6 @@ def __init__(
from matplotlib.widgets import LassoSelector

self.fig = ax.figure
self.canvas = ax.figure.canvas
self.collection = collection
self.names = names
self.alpha_selected = alpha_selected
Expand Down Expand Up @@ -1722,14 +1721,14 @@ def on_select(self, verts):

# Don't respond to single clicks without extra keys being hold down.
# Figures like plot_evoked_topo want to do something else with them.
if len(verts) <= 3 and self.canvas._key not in ["control", "ctrl+shift"]:
if len(verts) <= 3 and self.fig.canvas._key not in ["control", "ctrl+shift"]:
return

path = Path(verts)
inds = np.nonzero([path.intersects_path(p) for p in self.paths])[0]
if self.canvas._key == "control": # Appending selection.
if self.fig.canvas._key == "control": # Appending selection.
self.selection_inds = np.union1d(self.selection_inds, inds).astype("int")
elif self.canvas._key == "ctrl+shift":
elif self.fig.canvas._key == "ctrl+shift":
self.selection_inds = np.setdiff1d(self.selection_inds, inds).astype("int")
else:
self.selection_inds = inds
Expand All @@ -1739,9 +1738,9 @@ def on_select(self, verts):

def select_one(self, ind):
"""Select or deselect one sensor."""
if self.canvas._key == "control":
if self.fig.canvas._key == "control":
self.selection_inds = np.union1d(self.selection_inds, [ind])
elif self.canvas._key == "ctrl+shift":
elif self.fig.canvas._key == "ctrl+shift":
self.selection_inds = np.setdiff1d(self.selection_inds, [ind])
else:
return # don't notify()
Expand All @@ -1768,7 +1767,7 @@ def style_objects(self):
self.collection.set_facecolors(self.fc)
self.collection.set_edgecolors(self.ec)
self.collection.set_linewidths(self.lw)
self.canvas.draw_idle()
self.fig.canvas.draw_idle()

def disconnect(self):
"""Disconnect the lasso selector."""
Expand All @@ -1777,7 +1776,7 @@ def disconnect(self):
self.ec[:, -1] = self.alpha_selected
self.collection.set_facecolors(self.fc)
self.collection.set_edgecolors(self.ec)
self.canvas.draw_idle()
self.fig.canvas.draw_idle()


def _get_color_list(*, remove=None):
Expand Down