How to save the graph generated by mne.viz.plot_compare_evokeds

I want to ask how to save the graph generated by mne.viz.plot_compare_evokeds?

When I use evoke’s plot or joint plot function, I can only save the generated figure directly through savefig, but mne.viz.plot_compare_evokeds seems to generate a list of the figure(s). Then how should I save this What about graphics?

My code:

evoke_roi.plot(titles=dict(eeg=title), time_unit='s')
evoke_roiplt.savefig("evoke.png")
evoke.plot_joint(times=[0.1, 0.2, 0.32, 0.5])
evoke_plot_joint.savefig("evokejoint.png")
complt = mne.viz.plot_compare_evokeds(dict(auditory=aud_evoked, visual=vis_evoked))
complt.savefig(subject +'compareplot' + ".png")
Error:
AttributeError:'list' object has no attribute'figure'

I look forward to your reply.
thank you for your help!

  • MNE-Python version: MNE 0.22.0
  • operating system: mac 10.14.6, jupyter lab 3.0.5

According to the documentation, plot_compare_evokeds() returns a list of figures (one figure per channel type). You could try to save those individually; or you could create a figure containing one axes object per channel type and pass those to plot_compare_evokeds(), e.g.:

import matplotlib.pyplot as plt

fig, axes = plt.subplots(3)  # assuming 3 channel types
mne.viz.plot_compare_evokeds(dict(auditory=aud_evoked, visual=vis_evoked),
                             axes=axes)
fig.savefig(f'{subject}_compareplot.png')

Thank you very much for your reply!
This method can be run.
In addition, I found another way to save the generated graphics.

Method 1: (as your suggestion)
fig, axes = plt.subplots(1) # assuming 3 channel types
mne.viz.plot_compare_evokeds(dict(verbe1=verbevoke1, verbe2=verbevoke2), combine = “mean”,
axes=axes)
fig.savefig(f’{subject}_compareplot.png’)

Method 2:
compareplt = mne.viz.plot_compare_evokeds(dict(ver¡be1=verbevoke1, verbe2=verbevoke2), combine = “mean”,
split_legend = True,
ci = True)
compareplt[0].savefig(subject + “compareplot” + “.png”)