I would like to check what is the filter parameters of the mne.io.RawArray.plot() method? When I try to replicate the filter used in the plot function by looking at the log, I could not reconstruct the filtered signal. As shown in the code below code, the x_2.filter is trying to reconstruct the filter of the plot function.
Hello, the filters use the exact same settings, it’s really only the log message that’s different. It is emitted by Raw.filter() – which Raw.plot() doesn’t use (not sure why that is). We probably should ensure the log messages look the same.
The scalings are different in the two plots - make sure you set it to identical values. Also, the data scale is off by a factor of 1e6. EEG data are expected to be in V (and not µV) in MNE.
Thanks Clemens, after rescaling the plot though the filtered data are not identical, but they are mostly the same with some difference in the artefacts.
the following figures is generated with data
np.random.seed(11)
full_eeg = np.random.rand(31, 5000)
and if you plot with the two methods you will see a difference in the C3 channel at time 0, the above figure is >0 while the bottom figure is <0, the channel list is given: There are also other differences, which you can try to plot with the dummy random data, I think the filter setting for both methods are not identical which cause such differences.
Indeed these two methods yield different results. I used the following code:
import numpy as np
import mne
np.random.seed(11)
data = np.random.rand(31, 5000) * 5e-5
info = mne.create_info(31, 256, "eeg")
raw = mne.io.RawArray(data, info)
l_freq = 0.5
h_freq = 40
order = 2
method = "iir"
iir_params = dict(order=order, output="sos", ftype="butter")
raw.plot(n_channels=8, lowpass=h_freq, highpass=l_freq, filtorder=order,
remove_dc=False, title="Filtered in plot")
raw_filtered = raw.copy().filter(l_freq, h_freq, method=method,
iir_params=iir_params)
raw_filtered.plot(n_channels=8, remove_dc=False, title="Filtered")
The data filtered inside plot is different at the end of each visible window. I think this could be due to how the filter is applied - it looks like it’s applied to the visible data only, whereas pre-filtering and then plotting filters the entire signal.
You can use the scalings argument in raw.plot(). However, it won’t be easy to set a specific µV/mm scaling, because that would depend on your screen resolution and size.