Skip to content

Conversation

@tacaswell
Copy link
Contributor

Matplotlib may change the canvas object on a figure. It is better to
ask the figure what its current canvas is rather than cache the one it has the
first time you see it.

Reference issue (if any)

This may address the new issues idenitfied in

matplotlib/matplotlib#30575

What does this implement/fix?

In mpl 3.11 we are being better about cleaning up GUI state on Figures when
they are closed. As part of this, when closed the canvas is replaced with a
base non-operative canvas. We think that because mne is caching the initial
GUI/Agg canvas the tear down callbacks are driving the figure to a chimera state
that is the source of the problems.

Additional information

Matplotlib may change the canvas object on a figure.  It is better to
ask the figure what its current canvas is rather than cache the one it has the
first time you see it.
Copy link
Member

@larsoner larsoner left a comment

Choose a reason for hiding this comment

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

LGTM marking for merge-when-green, thanks for the thorough investigation @tacaswell !

Comment on lines -328 to -330
# 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))
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...

.. _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

@larsoner larsoner enabled auto-merge (squash) January 23, 2026 00:34
@larsoner larsoner disabled auto-merge January 23, 2026 00:34
@larsoner larsoner enabled auto-merge (squash) January 23, 2026 00:34
@larsoner larsoner merged commit 1ebb93e into mne-tools:main Jan 23, 2026
32 checks passed
@welcome
Copy link

welcome bot commented Jan 23, 2026

🎉 Congrats on merging your first pull request! 🥳 Looking forward to seeing more from you in the future! 💪

@tacaswell tacaswell deleted the fix/canvas_caching branch January 23, 2026 03:46
larsoner added a commit to teonbrooks/mne-python that referenced this pull request Jan 30, 2026
* upstream/main: (23 commits)
  DOC: Add jupyterlite idea to roadmap (mne-tools#13620)
  MAINT: Use f-strings in test_import_nesting.py (mne-tools#13551)
  Improve docs for raw.to_data_frame (mne-tools#13590)
  Sensitivity map doc improved (mne-tools#13578)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#13612)
  MAINT: Fix for latest SciPy (mne-tools#13613)
  Fix pre-commit call in SPEC0 action [ci skip] (mne-tools#13609)
  MAINT: Add mne-denoise to CI dependencies (mne-tools#13607)
  FIX: do not cache canvas object (mne-tools#13606)
  FIX: Set calibration plot axes to screen resolution if available (mne-tools#13558)
  Refactoring eyetracking.py (mne-tools#13602)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#13601)
  Follow up PR to PR - mne-tools#13596 (mne-tools#13599)
  FIX: Sphinx (mne-tools#13600)
  Doc improvement - Examples using <some-method> section quirk fix (mne-tools#13596)
  Add more information to eSSS in examples and docsstring (mne-tools#13591)
  np.fix -> np.trunc (deprecation) (mne-tools#13594)
  Make mne.sys_info() work with powershell 7+ (mne-tools#13593)
  BUG: Fix minor bug with T1 check (mne-tools#13588)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#13587)
  ...
larsoner added a commit to contsili/mne-python that referenced this pull request Jan 30, 2026
* upstream/main: (67 commits)
  DOC: Add jupyterlite idea to roadmap (mne-tools#13620)
  MAINT: Use f-strings in test_import_nesting.py (mne-tools#13551)
  Improve docs for raw.to_data_frame (mne-tools#13590)
  Sensitivity map doc improved (mne-tools#13578)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#13612)
  MAINT: Fix for latest SciPy (mne-tools#13613)
  Fix pre-commit call in SPEC0 action [ci skip] (mne-tools#13609)
  MAINT: Add mne-denoise to CI dependencies (mne-tools#13607)
  FIX: do not cache canvas object (mne-tools#13606)
  FIX: Set calibration plot axes to screen resolution if available (mne-tools#13558)
  Refactoring eyetracking.py (mne-tools#13602)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#13601)
  Follow up PR to PR - mne-tools#13596 (mne-tools#13599)
  FIX: Sphinx (mne-tools#13600)
  Doc improvement - Examples using <some-method> section quirk fix (mne-tools#13596)
  Add more information to eSSS in examples and docsstring (mne-tools#13591)
  np.fix -> np.trunc (deprecation) (mne-tools#13594)
  Make mne.sys_info() work with powershell 7+ (mne-tools#13593)
  BUG: Fix minor bug with T1 check (mne-tools#13588)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#13587)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants