Skip to content

Fix top and bottom clipping in raw.plot()#13787

Open
cbrnr wants to merge 3 commits intomne-tools:mainfrom
cbrnr:raw-plot-annotations-clip
Open

Fix top and bottom clipping in raw.plot()#13787
cbrnr wants to merge 3 commits intomne-tools:mainfrom
cbrnr:raw-plot-annotations-clip

Conversation

@cbrnr
Copy link
Copy Markdown
Contributor

@cbrnr cbrnr commented Mar 25, 2026

Previously, annotation labels positioned above the plot, as well as the x-axis label below it, were clipped and therefore unreadable using the matplotlib backend.

This PR addresses the issue by repositioning annotation labels within the plot area and increasing the bottom spacing to ensure the x-axis label is fully visible.

Before:
before

After:
after

Note that I've observed these issues on Linux, so I think it would be good to verify that the changes still render correctly also on macOS and Windows.

from numpy.random import default_rng

import mne
from mne import create_info
from mne.io import RawArray

mne.viz.set_browser_backend("matplotlib")


def create_toy_data(n_channels=3, duration=25, sfreq=250, seed=None):
    rng = default_rng(seed)
    data = rng.standard_normal(size=(n_channels, duration * sfreq)) * 5e-6
    info = create_info(n_channels, sfreq, "eeg")
    return RawArray(data, info)


raw = create_toy_data()
raw.set_annotations(
    mne.Annotations(onset=[1, 5], duration=[1, 2], description=["test", "bad"])
)
raw.plot(block=True)

@cbrnr cbrnr requested a review from drammock as a code owner March 25, 2026 13:58
@cbrnr cbrnr marked this pull request as draft March 25, 2026 14:01
@cbrnr
Copy link
Copy Markdown
Contributor Author

cbrnr commented Mar 25, 2026

Still looks good on macOS, even though the fix was not needed there.

Before:
before

After:
after

@cbrnr
Copy link
Copy Markdown
Contributor Author

cbrnr commented Mar 26, 2026

Looks good on Windows too.

Before:
before

After:
after

@cbrnr cbrnr marked this pull request as ready for review March 26, 2026 05:51
@cbrnr
Copy link
Copy Markdown
Contributor Author

cbrnr commented Mar 26, 2026

If events are also present, the plot still looks fine (I've increased the annotations z-order such that the vertical event line is behind):

Screenshot 2026-03-26 at 08 02 30

@wmvanvliet
Copy link
Copy Markdown
Contributor

I'm on linux too and don't seem to get your bug:

20260329_12h22m34s_grim

The like the yourchanges to the margins though, looks a bit better to me.

@cbrnr
Copy link
Copy Markdown
Contributor Author

cbrnr commented Mar 29, 2026

Could be related to Wayland vs. X11. What do you use? But as you said, I also think that it looks better with the new layout.

@wmvanvliet
Copy link
Copy Markdown
Contributor

wmvanvliet commented Mar 30, 2026

Tested on both XWayland (QT_QPA_PLATFORM=xcb) and Wayland proper (QT_QPA_PLATFORM=wayland-egl). Both look fine.

@cbrnr
Copy link
Copy Markdown
Contributor Author

cbrnr commented Mar 30, 2026

I can reproduce the issue on two different machines. Whatever the difference is, you agree that the new layout is better, right?

@wmvanvliet
Copy link
Copy Markdown
Contributor

I wonder what causes the difference on your machine (just tested on another linux machine... works fine). But yes, I'm not against this change, because on my machines the new version also works great and it if fixes things for your machine then perhaps there are other machines out there with the same issue.

@wmvanvliet
Copy link
Copy Markdown
Contributor

sorry about the previous comment. That was not meant for this thread at all, nothing is broken for me 😄

@cbrnr cbrnr force-pushed the raw-plot-annotations-clip branch from 27f42ef to 07ef170 Compare March 30, 2026 10:36
@cbrnr
Copy link
Copy Markdown
Contributor Author

cbrnr commented Mar 30, 2026

@drammock and/or @larsoner this is ready for review.

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