Misaligned viz.plot_compare_evokeds

Hi, I’m trying to use viz.plot_compare_evokeds to obtain an ERP plot per channel in the same figure. What I get is a figure that in which axes are not aligned, ticks are not in the correct axes, among others, see below:

  • MNE-Python version: 0.23.4
  • operating system: CentOS Linux 7
ranges = (0, 30), (30, 100), (100, 300)
labels = "near", "mid", "far"
ch_include = ["Fz", "Pz", "P8"]
ranges = make_distance_conditions(ranges, labels, take_farther=True)

evoked = {dist_range: [] for dist_range in ranges["label"]}
for sub in subjects:
    for _, series in bins.iterrows():
        ave = sub.epochs[series["query"]].average(picks=ch_include)
        evoked[series["label"]].append(ave)


plt.close("all")
figs = mne.viz.plot_compare_evokeds(evoked, picks=ch_include, axes="topo")
path = _paths.FIGURES_DIR / "erp-distances.jpg"
figs[0].savefig(path)

Before trying something else, how does this look to you? Could it be a bug or my mistake? Thanks!

axes='topo' is the reason. It’s creating the axes in a spatial layout corresponding to the layout of the sensors. Try changing ch_include to include other or different sensors and you’ll see.

Thanks. I see, the thing is that I want exactly Fz, Pz, and P8. Even if say that the layout (XY placement of 3 ERP plots in the figure plane) is correct, the axes ticks and titles are still messed up. I wanted to double check before filling a bug report in GitHub.

you can pre-generate 3 axes with matplotlib, then plot to each one in turn using one of your 3 channels. something like

fig, axs = plt.subplots(1, 3)
for ch_name, ax in zip(ch_include, axs):
    plot_compare_evokeds(evoked, picks=ch_name, axes=ax)

If you don’t want them all in a row as subplots, then you have all of matplotlib’s power at your disposal to place the axes wherever you want (fig = plt.figure() followed by 3 calls to fig.add_axes(...), placing them wherever you want within the figure).

Yes, thanks, that would be a way to rearrange the plots. But please read my previous message and see the figure from the original post. I’m mostly concerned about how ticks (numbers in the axis) seem to appear in the wrong locations.

A call with the argument “axis=‘topo’” would give a subplot arrangement that I may like or not, but it should produce correct axes ticks and titles.

@c-torre , I’ve never used axes='topo' but the ticks and some axes lines indeed seem to be positioned incorrectly. Looks like a bug to me.

1 Like

Thanks. When I get some time I can try to replicate with the sample dataset and move this to GitHub.

1 Like

feel free to just open the issue with a link to this thread, since I’m pretty sure I realize now what the problem is (and sorry for not reading your reply carefully enough). plot_compare_evokeds(..., axes='topo') tries to create an extra axis that shows only the axis spines, ticklabels, and axis labels. It looks like that “legend axis” is getting plotted on top of the axis for P8

2 Likes

A pull request to fix this issue is at fix plot_compare_evokeds topo legend axes placement by drammock · Pull Request #9927 · mne-tools/mne-python · GitHub

2 Likes