Skip to content

BUG: epoch_colors desynchronize when scrolling in EEG plots in default backend #408

@DavoudYneuro

Description

@DavoudYneuro

Description of the problem

When using the epoch_colors parameter in MNE's epochs.plot() function, the custom colors display correctly on the initial view but become desynchronized when scrolling, resizing, or interacting with the plot. Instead of showing properly colored EEG traces, the plot shows vertical lines or color boxes overlaid on the data.

Affected Versions

  • MNE-Python: All versions with epoch_colors support
  • mne-qt-browser: All versions (default backend)
  • Backends affected: Both Qt (mne-qt-browser) and Matplotlib

Steps to reproduce

import mne
import numpy as np

# Create sample epochs
info = mne.create_info(ch_names=['Fz', 'Cz', 'Pz', 'Oz'], sfreq=256., ch_types='eeg')
n_epochs = 50
n_channels = 4
n_times = 256
data = np.random.randn(n_epochs, n_channels, n_times) * 1e-6

epochs = mne.EpochsArray(data, info)

# Create custom epoch_colors with distinct patterns
# This makes it easy to see if colors are misaligned
epoch_colors = []
for i in range(n_epochs):
    if i % 5 == 0:
        colors = ['red', 'blue', 'red', 'red']  # Every 5th epoch is red
    elif i % 3 == 0:
        colors = ['blue', 'blue', 'red', 'blue']  # Every 3rd epoch is blue
    elif i % 2 == 0:
        colors = ['green', 'black', 'green', 'green']  # Even epochs are green
    else:
        colors = ['black', 'black', 'green', 'black']  # Odd epochs are black
    epoch_colors.append(colors)

# Plot with custom epoch_colors
fig = epochs.plot(epoch_colors=epoch_colors, n_epochs=10, block=True)


# STEPS TO REPRODUCE:
# 1. Initial view shows epochs ✓ CORRECT
# 2. Press Page Down or scroll right
# 3. View now shows other epochs
# 4. BUG: Colors show as vertical lines or are at wrong positions ✗ BROKEN

Expected results

Custom colors assigned to specific epochs via the epoch_colors parameter should:

  • Display correctly on initial render
  • Remain synchronized with their assigned epochs when scrolling
  • Maintain correct colors when resizing the window
  • Show colored EEG traces (not vertical lines or boxes)
Image

Actual results

  • Initial view: Colors display correctly
  • After scrolling: Colors become desynchronized, showing:
    • Vertical lines instead of colored traces
    • Color boxes/rectangles overlaying the EEG data
    • Colors appearing at wrong epoch positions
    • Random color patterns unrelated to the assigned colors
Image

Additional information

Screen.Recording.2026-04-24.at.16.10.27.mov

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions