Skip to content

Export as vector based graphics (SVG, EPS, PDF) throws an error for Evoked.plot() #13242

Open
@sjentsch

Description

@sjentsch

Description of the problem

When using Evoked.plot() (assigning it to a figure handle) and then trying to export from that figure handle to a vector graphic (SVG, EPS or PDF), I get error messages like the one below (one for each axis / plot in the figure). Exporting as PNG works fine. Apparently, there seems to be a missing attribute copy_from_bbox.

Traceback (most recent call last):
  File "/opt/Software4EEG/MNE/lib/python3.12/site-packages/matplotlib/cbook.py", line 361, in process
    func(*args, **kwargs)
  File "/opt/Software4EEG/MNE/lib/python3.12/site-packages/matplotlib/widgets.py", line 2167, in update_background
    self.background = self.canvas.copy_from_bbox(self.ax.bbox)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'FigureCanvasSVG' object has no attribute 'copy_from_bbox'

Steps to reproduce

Use the code and the data from https://mne.tools/stable/auto_examples/visualization/channel_epochs_image.html (up to where epochs is created). Afterwards, use:
fig = epochs.average().plot()
fig.savefig('Trial.svg')
The error thrown after calling the last command.
fig.savefig('Trial.png') works without any problem, i.e., it is not a problem with generating the plot itself.

Link to data

See above. But I assume, it would produce the error whenever one assigns Evoked.plot() to a figure handle and then tries to save a vector graphics (that requires a bounding box).

Expected results

Export of the figure without any error messages.

Additional information: It appears as if in some cases the exported figures can be read by Inkscape, in other cases they seem to contain mistakes and Inkscape crashes. I could not determine yet, why the exported figures sometimes seems to have valid format.

Actual results

Export of the figure with an error message.

Resulting SVG-files work sometimes, but not always.

Additional information

Platform             Linux-6.11.0-21-generic-x86_64-with-glibc2.39
Python               3.12.3 (main, Feb  4 2025, 14:48:35) [GCC 13.3.0]
Executable           /opt/Software4EEG/MNE/bin/python
CPU                  Intel(R) Core(TM) Ultra 5 135U (14 cores)
Memory               30.8 GiB

Core
├☑ mne               1.9.0 (latest release)
├☑ numpy             2.2.4 (OpenBLAS 0.3.28 with 14 threads)
├☑ scipy             1.15.2
└☑ matplotlib        3.10.1 (backend=qtagg)

Numerical (optional)
├☑ sklearn           1.6.1
├☑ h5io              0.2.4
├☑ h5py              3.13.0
└☐ unavailable       numba, nibabel, nilearn, dipy, openmeeg, cupy, pandas

Visualization (optional)
├☑ qtpy              2.4.3 (PySide6=6.9.0)
├☑ pyqtgraph         0.13.7
├☑ mne-qt-browser    0.7.1
└☐ unavailable       pyvista, pyvistaqt, vtk, ipympl, ipywidgets, trame_client, trame_server, trame_vtk, trame_vuetify

Ecosystem (optional)
├☑ mne-bids          0.16.0
├☑ mne-icalabel      0.7.0
├☑ edfio             0.4.8
├☑ pybv              0.7.6
└☐ unavailable       mne-nirs, mne-features, mne-connectivity, mne-bids-pipeline, neo, eeglabio, mffpy

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions