# Misaligned viz.plot\_compare\_evokeds

**URL:** <https://mne.discourse.group/t/misaligned-viz-plot-compare-evokeds/3834>\
**Category:** Support & Discussions\
**Tags:** eeg, visualization, evoked\
**Created:** [October 19, 2021, 2:46pm UTC](https://mne.discourse.group/t/misaligned-viz-plot-compare-evokeds/3834 "2021-10-19T14:46:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![c-torre](https://avatars.discourse-cdn.com/v4/letter/c/e480ec/32.png) [@c-torre](https://mne.discourse.group/u/c-torre)\
**Post date:** [October 19, 2021, 2:46pm UTC](https://mne.discourse.group/t/misaligned-viz-plot-compare-evokeds/3834/1 "2021-10-19T14:46:50Z")

</div>

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:

 ![misaligned-erp-distances](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/b89eb985133e6f53e981617f31cbd43045887b94.jpeg)

- MNE-Python version: 0.23.4
- operating system: CentOS Linux 7

```python
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!

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [October 22, 2021, 7:57pm UTC](https://mne.discourse.group/t/misaligned-viz-plot-compare-evokeds/3834/2 "2021-10-22T19:57:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![c-torre](https://avatars.discourse-cdn.com/v4/letter/c/e480ec/32.png) [@c-torre](https://mne.discourse.group/u/c-torre)\
**Post date:** [October 25, 2021, 8:51am UTC](https://mne.discourse.group/t/misaligned-viz-plot-compare-evokeds/3834/3 "2021-10-25T08:51:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [October 25, 2021, 10:13pm UTC](https://mne.discourse.group/t/misaligned-viz-plot-compare-evokeds/3834/4 "2021-10-25T22:13:51Z")

</div>

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

```python
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).

---

<div class="post-metadata">

**Author:** ![c-torre](https://avatars.discourse-cdn.com/v4/letter/c/e480ec/32.png) [@c-torre](https://mne.discourse.group/u/c-torre)\
**Post date:** [October 26, 2021, 7:43am UTC](https://mne.discourse.group/t/misaligned-viz-plot-compare-evokeds/3834/5 "2021-10-26T07:43:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mmagnuski](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mmagnuski/32/153_2.png) [@mmagnuski](https://mne.discourse.group/u/mmagnuski)\
**Post date:** [October 26, 2021, 11:22am UTC](https://mne.discourse.group/t/misaligned-viz-plot-compare-evokeds/3834/6 "2021-10-26T11:22:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![c-torre](https://avatars.discourse-cdn.com/v4/letter/c/e480ec/32.png) [@c-torre](https://mne.discourse.group/u/c-torre)\
**Post date:** [October 26, 2021, 11:27am UTC](https://mne.discourse.group/t/misaligned-viz-plot-compare-evokeds/3834/7 "2021-10-26T11:27:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [October 26, 2021, 3:41pm UTC](https://mne.discourse.group/t/misaligned-viz-plot-compare-evokeds/3834/8 "2021-10-26T15:41:01Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [October 30, 2021, 12:51am UTC](https://mne.discourse.group/t/misaligned-viz-plot-compare-evokeds/3834/9 "2021-10-30T00:51:14Z")

</div>

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](https://github.com/mne-tools/mne-python/pull/9927)
