MRG, VIZ, MAINT: figure class proof-of-concept#7955
MRG, VIZ, MAINT: figure class proof-of-concept#7955agramfort merged 177 commits intomne-tools:masterfrom
Conversation
b511b7c to
6bd7adb
Compare
|
I haven't seen any discussion on how to implement dark mode - what's the plan? Add a |
|
The plan is to not get in the way of existing matplotlib theme functionality. In other words, use rcparams entries for things like foreground and background, and references to the color cycle like 'C2' for accent color needs. |
|
this is ready for preliminary testing / review from anyone interested (@cbrnr? @hoechenberger?). For ease of side-by-side comparison, the new plotting function is implemented as import os
import numpy as np
import matplotlib.pyplot as plt
import mne
plt.ion()
sample_data_folder = mne.datasets.sample.data_path()
sample_data_raw_file = os.path.join(sample_data_folder, 'MEG', 'sample',
'sample_audvis_raw.fif')
raw = mne.io.read_raw_fif(sample_data_raw_file, verbose=False)
raw.apply_proj()
ecg_proj_file = os.path.join(sample_data_folder, 'MEG', 'sample',
'sample_audvis_ecg-proj.fif')
ecg_projs = mne.read_proj(ecg_proj_file)
raw.add_proj(ecg_projs)
sample_data_noise_cov_file = os.path.join(sample_data_folder, 'MEG', 'sample',
'ernoise-cov.fif')
noise_cov = mne.read_cov(sample_data_noise_cov_file)
events = mne.find_events(raw, stim_channel='STI 014')
event_dict = {'auditory/left': 1, 'auditory/right': 2}
event_color = {1: 'r', 2: 'g', -1: 'y'}
annotations = mne.Annotations(onset=(2, 3, 5), duration=(0.5, 2.5, 1),
description=('foo', 'bar', 'bad_baz'))
raw.set_annotations(annotations)
fig = mne.viz.raw.plot_raw_alt(
raw, proj=True, events=events, event_id=event_dict,
event_color=event_color, noise_cov=noise_cov,
group_by='selection', butterfly=False, decim=2,
show_options=True)Known deficiencies:
|
|
@drammock I'd love to test this next week (I'm currently on vacation). |
|
@drammock Will taste later today! |
|
@drammock So you switched clamping back to using np.clip instead of masked arrays? Why's that? |
|
Because I realized that "clamp" (as in voltage clamp) had a particular meaning and users would expect to see flat lines (rather than empty space) where the signal exceeded its limits. I still use masked arrays (instead of a clipping mask) for the other case. |
|
tested locally. Works great ! |
|
Looks really good! Here are a few differences I've noticed, not sure if they are intentional or not, but they're maybe worth discussing:
|
This truncation to 60 characters was previously only done when
The yellowish was an early decision to go with the matplotlib cycler colors for everything (in hopes of making dark mode work via
Personally I'm in favor of marking bads only when clicking channel names (not data traces). But this is a UI change that might upset many users. Note that getting the "hit" logic correct for the traces is surprisingly tricky; MPL provides a
I like the colored version too, but I've reverted to black for now (it was not an intentional change).
This was an unintentional change and has been fixed.
Good idea, will do.
That was a result of testing cruft (I had briefly commented out the lines that handle it). Fixed now.
Italicized channel names is done when channels are whitened (toggle with
This is a "feature" of
Surprisingly tricky. Working on it. |
|
Regarding the green line, what about continuously reporting the time under the mouse cursor somewhere in the plot or in a separate (toggle-able statusbar)? This would make the green line unnecessary (not that anyone would notice because it's so hard to get it to appear in the first place). |
|
@larsoner this may be close to ready for your eyes. Summary of where things stand:
Do you have any suggestions / ideas / advice about which way might be most promising to go on these issues? |
|
I was able to create a compound path to mask the That is implemented on FWIW here's what the I'm beginning to think that the only way to significantly speed this up is to use blitting for everything. In which case I suggest moving forward with reviewing/merging this one after I fix the clipping and clean up the cruft, and doing the blitting in a separate PR. |
Could be. So maybe go back to Line2D and we'll try to speed up by blitting only the things we need to blit? |
1d4eda5 to
a32925b
Compare
I've reverted the
|
Want to get CIs happy first, then I'll look? |
|
@larsoner last CI run everything passed except coverage and one Travis run. I've just pushed some commits that should help coverage. The travis failures were all |
|
These errors look legitimate (tick numbers and BAD_ vs BAD): For the mpl_connect thing, maybe this: https://stackoverflow.com/questions/31933393/event-handling-matplotlibs-figure-and-pyplots-figure But if it's happening on our minimal/old deps build, I would try replicating that environment locally. Then you should see the same error. It could be it's a matplotlib bug that has been fixed and maybe we need to either |
Argh, that's a new one I just introduced.
Yep, now I get that locally.
Will see if I can find out when this behavior changed in MPL and/or how to work around it with old MPL. |
|
Thanks @drammock for doing this amazing work! And sorry for being so late providing feedback. I just gave the Raw browser a shot. Here's what I've found on macOS with
|
d5b48e2 to
d4c5da7
Compare
|
ok @larsoner I've restored channel type plotting order, and CIs are still happy (except codecov, which should improve once ICA uses the figure class, because old code that has unhit lines will get removed) |
larsoner
left a comment
There was a problem hiding this comment.
LGTM +1 for merge
@agramfort do you want to look before merge?
|
looking now !
… |
|
🥳 |
|
@agramfort did you forget to sqash-merge? |
|
If so we should undo and force push a squashed version because of the number of commits |
|
Just force-pushed to master. 😨 please check to make sure I didn't do something wonky. |
Can we make master a protected branch to prevent such accidents in the future? |
|
The accident was actually pushing the green button the wrong way, and the fix was a force push that would not have been allowed under the protection rules. FWIW so far I've seen more harm / wasted time from protected branches than good on other repos. What we could maybe do is only allow the squash and merge option for the green button on this repo. That would have prevented the issue and shouldn't add much if any maintenance overhead. Rebase or standard merge is used very rarely by us nowadays. |
|
Okay just changed it so that squash merge is the only choice. About once a year (at most) I've wanted to do a different type (the highly collaborative beamforming PR is the only one I remember) and I'm okay with doing that manually from the command line or temporarily enabling another mode when needed. |






This is an element of #7751. It defines new classes:
MNEFigParams(a simple attribute container)MNEFigure(wrapper formatplotlib.figure.Figurewith our params added)MNEBrowseFigure(Figure class for raw.plot, ica.plot, epochs.plot)So far just laying down the infrastructure, none of the instance methods are actually using the new classes yet. If anyone wants to play around with it: