Skip to content

Add option to show a zero line in browser#14018

Open
cbrnr wants to merge 2 commits into
mne-tools:mainfrom
cbrnr:browser-horizontal-zero
Open

Add option to show a zero line in browser#14018
cbrnr wants to merge 2 commits into
mne-tools:mainfrom
cbrnr:browser-horizontal-zero

Conversation

@cbrnr

@cbrnr cbrnr commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

This PR adds an option to show a zero line (toggleable with "0") to the Matplotlib backend. I've implemented this feature for the Qt backend in mne-tools/mne-qt-browser#423.

Short example:

import numpy as np

import mne

mne.viz.set_browser_backend("matplotlib")

sfreq = 200.0
n_channels = 20
t = np.arange(int(60 * sfreq)) / sfreq

rng = np.random.default_rng(0)
offsets = rng.uniform(-100e-6, 100e-6, size=n_channels)
data = rng.standard_normal((n_channels, t.size)) * 20e-6 + offsets[:, np.newaxis]

ch_names = [f"EEG {i + 1}" for i in range(n_channels)]
info = mne.create_info(ch_names, sfreq, "eeg")
raw = mne.io.RawArray(data, info)

raw.plot(show_zero_line=True, scalings=dict(eeg=100e-6), n_channels=5, block=True)

@cbrnr cbrnr requested a review from larsoner as a code owner July 3, 2026 12:11
@cbrnr

cbrnr commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

The docs error (AssertionError: Duplicates in PYPI_PACKAGES and installer packages: ['mne-kit-gui']) is very likely unrelated.

The Azure error is also unrelated (hitting 403: rate limit exceeded).

Comment thread mne/utils/docs.py
Comment on lines +4277 to +4279
initialized. The zero line marks the true zero of each channel's own
displayed trace, independent of any DC removal or highpass filtering
already applied to the data. Can be toggled after initialization by

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm somehow it's hard for me to parse this. I expected at first that hitting "d" would change the position of the line in the plot. I think calling it "true zero" made me think of "where zero actually is for the signal". So maybe

Suggested change
initialized. The zero line marks the true zero of each channel's own
displayed trace, independent of any DC removal or highpass filtering
already applied to the data. Can be toggled after initialization by
initialized. The zero line marks the centering point of each channel's
**displayed trace**, independent of any DC removal or highpass filtering
already applied to the data. Can be toggled after initialization by

I wonder if there is value in having a third mode where toggling DC removal changes where the "zero line" is displayed so that it's actually at where the zero level is for that channel (in other words, treating "DC removal" as more of a visual vertical translation rather than a subtraction of any values from the trace)

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