ENH: Add time_format to Raw.plot()#9419
Conversation
|
I tried many ways of escaping in RST, but none allowed me to include "%" from the datetime format code. |
|
When I try to build the documentation with I assume it is not related to the changes from this PR, right?. I already updated my sphinx-installation from |
|
your doc CIs are green. Do you have this pb locally? |
Yes, its locally (on Windows). I reinstalled my mnedev-environment, but the error persists. |
|
And locally I can't replicate the error in test_epochs::test_metadata from the CIs: |
|
I pushed a fix for that in #9422, feel free to ignore it. It's due to using latest NumPy where they've deprecated something |
|
I have two additional suggestions that I'd like to discuss:
WDYT? Does anyone have a suggestion for a better parameter name instead of |
agramfort
left a comment
There was a problem hiding this comment.
I tested on some over night sleep EEG data and it worked great.
I am thinking we should be able to toggle the time format with eg the 't' shortcut. Doing so I am less worried about parameter API so I will expect users to toggle from the GUI the option.
my 2c
|
@agramfort, @cbrnr Thank you for the comments&ideas, I will look into the toggle-behaviour and the zoom-dependent format-changes. |
|
For the API, what about |
|
For the API, what about time_format = 'float' | 'datetime' ?
I like that !
|
|
If you view the plot with a "usual" duration-window, milliseconds aren't probably that important. By adding up |
|
I don't quite understand - can you show a figure that demonstrates the problem (and also your suggested solution/workaround)? |
|
@marsipu at the higher level zoom the times are out of order (55, 56.5, 56, 57.5, 57) in your screenshot |
Ah thanks, I overlooked it. The problem was: seconds = int(xval + first_time)which also added up milliseconds. I changed it to: seconds = int(xval) + int(first_time)What do you think about introducing this small artificial offset in favor of visualization? I also added the offset to the x-axis-label now so it would be transparent: |
|
I would only show fractions of a second when necessary (i.e. when zoomed in enough). So even if |
|
To summarize:
We could also display the exact time (not rounded) only when zooming in. The only thing that could be confusing for the user would be then, that |
|
Could we programmatically change the sub-second rounding level based on duration shown (zoom)? For example something like this, showing how |
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
Co-authored-by: Clemens Brunner <clemens.brunner@gmail.com>
The current approach is "always change by one second, unless that would be less than 3 samples, in which case show 3 samples (because anything less than 3 samples is unintelligible)". I don't consider that "broken" (@marsipu has already made it so that going back from 3 samples to 1 second works properly --- i.e., it no longer goes from 3 samples to 1 second + 3 samples), but I can agree that it might sometimes be useful to have access to zoom levels less than 1 second but more than 3 samples. That is what I thought you wanted, which is why I implemented the pseudo-logarithmic approach. Did you actually try it out, and find it worse than the 1-second-at-a-time zooming? If so, then what other approach do you propose? |
|
So in short currently it is not possible to zoom in less than one second because it immediately goes to three samples? I haven't tried your suggestion because I wanted to understand the current behavior, so I will now try it out! It would probably make sense to always zoom by a factor of two, let's see. |
Yes, this was true before @drammock's solution c524586. I like his new approach, because it provides small zoom-steps, keeps equal steps in both directions and also makes zooming-out faster which I would appreciate as a user. |
|
@drammock @marsipu I tested the new behavior and it is much better than the old one (I actually think the old one was broken because not being able to zoom in less than a second should have resulted in not zooming in any further instead of showing 3 samples). If we wanted to do some bikeshedding, we could try the factor 2 approach, but I'm also fine with what you already implemented. @marsipu regarding the clock labels, I think this is ready now. Very nice work, this is a badly needed feature! |
|
Thank you all for your support and improvements. |
|
OK, I've done one final pass over the code and played around some more with the feature interactively. I'm quite happy with how this turned out @marsipu! I added a couple more code comments, and tweaked the behavior very slightly:
+1 for merge when CIs are finished. |
|
Works great! I have one final (minor) nitpick, something which has been bothering me for a long time, and maybe this can be fixed here: there is no tick mark to the very right of the visualized time period. For example, the default duration is 10s, so I get labels 0, 2, 4, 6, 8 - but not 10. I'd find it super useful if the plot also showed the last time stamp (for both float and clock formats). Is this possible? |
The problem as I see it is, that |
|
Nice! I think it's really the range - with this change the last tick is now included! |
@cbrnr But not for the sample-data, right? |
|
Which sample data do you mean? I tried with |
I meant the dataset from |
|
Any particular file from this data set (can you provide the code)? |
import os
import mne
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(sample_data_raw_file)
raw.plot(block=True, duration=10) |
|
I see. That's a bit unfortunate, I'll think about it. But for some data sets at least it seems to improve things at least. |
|
I would try increasing the user-requested duration by one or two sampling periods, rather than using |
|
@drammock you mean just like that? Yeah, nice idea, this is so small that you wouldn't notice on the plot |
|
Good idea, now it also works for the sample data! 🥳 |





Reference issue
Tackles #9335 (@cbrnr).
What does this implement/fix?
This adds a parameter (time_format) to Raw.plot() to display the real time derived from Info['meas_date'].