# Filter parameters for mne.io.RawArray.plot()

**URL:** <https://mne.discourse.group/t/filter-parameters-for-mne-io-rawarray-plot/2719>\
**Category:** Support & Discussions\
**Tags:** eeg\
**Created:** [February 17, 2021, 3:50pm UTC](https://mne.discourse.group/t/filter-parameters-for-mne-io-rawarray-plot/2719 "2021-02-17T15:50:00Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![tcx](https://avatars.discourse-cdn.com/v4/letter/t/eada6e/32.png) [@tcx](https://mne.discourse.group/u/tcx)\
**Post date:** [February 17, 2021, 3:50pm UTC](https://mne.discourse.group/t/filter-parameters-for-mne-io-rawarray-plot/2719/1 "2021-02-17T15:50:00Z")

</div>

- MNE-Python version: 0.22.0
- Ubuntu 18.04.3 LTS:

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.

```
full_eeg_2 = copy.deepcopy(full_eeg)

x = mne.io.RawArray(full_eeg, info=data_info, verbose=True)
z = x.plot(scalings='auto', lowpass = 40, highpass=0.5, filtorder = 1, 
           remove_dc=False,verbose=True)
z.show
print("#" * 80)
x_2 = mne.io.RawArray(full_eeg_2, info=data_info, verbose=True)
x_2 = x_2.filter(l_freq=0.5, h_freq=40, method="iir",
                     iir_params=dict(order=1, ftype='butter', output="ba"))
z = x_2.plot(scalings='auto')
z.show

```

The following are the log for the two filtering function which are identical except for the line

“Filtering raw data in 1 contiguous segment”

```python
Creating RawArray with float64 data, n_channels=31, n_times=889240
    Range : 0 ... 889239 = 0.000 ... 3556.956 secs
Ready.
Setting up band-pass filter from 0.5 - 40 Hz

IIR filter parameters
---------------------
Butterworth bandpass zero-phase (two-pass forward and reverse) non-causal filter:
- Filter order 4 (effective, after forward-backward)
- Cutoffs at 0.50, 40.00 Hz: -6.02, -6.02 dB

################################################################################

Creating RawArray with float64 data, n_channels=31, n_times=889240
    Range : 0 ... 889239 = 0.000 ... 3556.956 secs
Ready.
Filtering raw data in 1 contiguous segment
Setting up band-pass filter from 0.5 - 40 Hz

IIR filter parameters
---------------------
Butterworth bandpass zero-phase (two-pass forward and reverse) non-causal filter:
- Filter order 4 (effective, after forward-backward)
- Cutoffs at 0.50, 40.00 Hz: -6.02, -6.02 dB

```

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [February 18, 2021, 8:11am UTC](https://mne.discourse.group/t/filter-parameters-for-mne-io-rawarray-plot/2719/2 "2021-02-18T08:11:56Z")

</div>

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.

@drammock might know more.

---

<div class="post-metadata">

**Author:** ![tcx](https://avatars.discourse-cdn.com/v4/letter/t/eada6e/32.png) [@tcx](https://mne.discourse.group/u/tcx)\
**Post date:** [February 18, 2021, 8:50am UTC](https://mne.discourse.group/t/filter-parameters-for-mne-io-rawarray-plot/2719/3 "2021-02-18T08:50:54Z")

</div>

Hi Richard,

But the filtered results are very different.

---

<div class="post-metadata">

**Author:** ![cbrnr](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/cbrnr/32/1409_2.png) [@cbrnr](https://mne.discourse.group/u/cbrnr)\
**Post date:** [February 18, 2021, 9:30am UTC](https://mne.discourse.group/t/filter-parameters-for-mne-io-rawarray-plot/2719/4 "2021-02-18T09:30:54Z")

</div>

Can you show us the difference? Can you maybe edit your example code so that it is fully reproducible (e.g. with toy data)?

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [February 18, 2021, 9:36am UTC](https://mne.discourse.group/t/filter-parameters-for-mne-io-rawarray-plot/2719/5 "2021-02-18T09:36:28Z")

</div>

> [@tcx](#):
>
> But the filtered results are very different.

The following works for me (I tried to extract the exact parameters that `Raw.plot()` would use):

```python
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')

l_freq = 0.5
h_freq = 40
order = 2
method = 'iir'
iir_params = dict(order=order, output='sos', ftype='butter')
n_channels = 2

raw = mne.io.read_raw_fif(sample_data_raw_file, preload=True)
raw_filtered = raw.copy().filter(l_freq=l_freq, h_freq=h_freq, method=method,
                                 iir_params=iir_params)

raw.plot(highpass=l_freq, lowpass=h_freq, filtorder=order,
         n_channels=n_channels, title='Raw')
raw_filtered.plot(n_channels=n_channels, title='Raw filtered')

```

---

<div class="post-metadata">

**Author:** ![tcx](https://avatars.discourse-cdn.com/v4/letter/t/eada6e/32.png) [@tcx](https://mne.discourse.group/u/tcx)\
**Post date:** [February 18, 2021, 9:50am UTC](https://mne.discourse.group/t/filter-parameters-for-mne-io-rawarray-plot/2719/6 "2021-02-18T09:50:17Z")

</div>

> [@richard](#):
>
> `iir_params`

 ![Screenshot 2021-02-18 at 5.48.35 PM](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/abfb732364804bad8394c72604c66b6c54ce9c58.jpeg) ![Screenshot 2021-02-18 at 5.48.51 PM](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/08a0c3383ee51f628636f3aeda725819cfd47196.jpeg)

The first screenshot is by the plot function,  
the below is filter + plot

---

<div class="post-metadata">

**Author:** ![tcx](https://avatars.discourse-cdn.com/v4/letter/t/eada6e/32.png) [@tcx](https://mne.discourse.group/u/tcx)\
**Post date:** [February 18, 2021, 9:56am UTC](https://mne.discourse.group/t/filter-parameters-for-mne-io-rawarray-plot/2719/7 "2021-02-18T09:56:00Z")

</div>

I tried with a dummy data, you can try to replicate by assigning full\_eeg to:  
np.random.seed(11)  
full\_eeg = np.random.rand(31, 5000)

which will produce different results

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [February 18, 2021, 9:56am UTC](https://mne.discourse.group/t/filter-parameters-for-mne-io-rawarray-plot/2719/8 "2021-02-18T09:56:35Z")

</div>

Without a fully reproducible example, I’m afraid we cannot help

---

<div class="post-metadata">

**Author:** ![cbrnr](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/cbrnr/32/1409_2.png) [@cbrnr](https://mne.discourse.group/u/cbrnr)\
**Post date:** [February 18, 2021, 10:04am UTC](https://mne.discourse.group/t/filter-parameters-for-mne-io-rawarray-plot/2719/9 "2021-02-18T10:04:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tcx](https://avatars.discourse-cdn.com/v4/letter/t/eada6e/32.png) [@tcx](https://mne.discourse.group/u/tcx)\
**Post date:** [February 18, 2021, 10:16am UTC](https://mne.discourse.group/t/filter-parameters-for-mne-io-rawarray-plot/2719/10 "2021-02-18T10:16:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cbrnr](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/cbrnr/32/1409_2.png) [@cbrnr](https://mne.discourse.group/u/cbrnr)\
**Post date:** [February 18, 2021, 10:17am UTC](https://mne.discourse.group/t/filter-parameters-for-mne-io-rawarray-plot/2719/11 "2021-02-18T10:17:48Z")

</div>

They should be exactly identical though. When you set a fixed scaling in both plots, can you highlight one of the differences you noticed?

---

<div class="post-metadata">

**Author:** ![tcx](https://avatars.discourse-cdn.com/v4/letter/t/eada6e/32.png) [@tcx](https://mne.discourse.group/u/tcx)\
**Post date:** [February 18, 2021, 4:25pm UTC](https://mne.discourse.group/t/filter-parameters-for-mne-io-rawarray-plot/2719/12 "2021-02-18T16:25:34Z")

</div>

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.

[“Fp1”, “Fp2”,“F7”,“F3”,“Fz”,“F4”,“F8”,“FT7”,“FC3”,“FCz”,“FC4”,“FT8”,“T7”,“C3”,“Cz”,“C4”,“T8”, “CP3”,  
“CPz”,“CP4”,“TP8”,“P7”,“P3”, “Pz”,“P4”,“P8”,“O1”,“Oz”,“O2”,“PO1”, “PO2”]

 ![Screenshot 2021-02-19 at 12.22.47 AM](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/40a96e1d54dfe92c14dd4767a8ee4c66bcf963d3.png)

 ![Screenshot 2021-02-19 at 12.21.44 AM](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/2166fe9af30abbf3c96cf6dce6c9d5de66be308a.png)

---

<div class="post-metadata">

**Author:** ![cbrnr](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/cbrnr/32/1409_2.png) [@cbrnr](https://mne.discourse.group/u/cbrnr)\
**Post date:** [February 18, 2021, 7:43pm UTC](https://mne.discourse.group/t/filter-parameters-for-mne-io-rawarray-plot/2719/13 "2021-02-18T19:43:15Z")

</div>

Indeed these two methods yield different results. I used the following code:

```python
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.

---

<div class="post-metadata">

**Author:** ![agramfort](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@agramfort](https://mne.discourse.group/u/agramfort)\
**Post date:** [February 18, 2021, 8:44pm UTC](https://mne.discourse.group/t/filter-parameters-for-mne-io-rawarray-plot/2719/14 "2021-02-18T20:44:06Z")

</div>

yes raw.plot does not apply filtering on the full data but but on the page you’re viewing and maybe a bit before  
and after.

Alex

---

<div class="post-metadata">

**Author:** ![tcx](https://avatars.discourse-cdn.com/v4/letter/t/eada6e/32.png) [@tcx](https://mne.discourse.group/u/tcx)\
**Post date:** [July 6, 2021, 10:52am UTC](https://mne.discourse.group/t/filter-parameters-for-mne-io-rawarray-plot/2719/15 "2021-07-06T10:52:01Z")

</div>

I have a question regarding the scaling of the plot. If I want to display my data with x microvolt/mm. How should I set my scale to achieve this?

---

<div class="post-metadata">

**Author:** ![cbrnr](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/cbrnr/32/1409_2.png) [@cbrnr](https://mne.discourse.group/u/cbrnr)\
**Post date:** [July 7, 2021, 1:15pm UTC](https://mne.discourse.group/t/filter-parameters-for-mne-io-rawarray-plot/2719/16 "2021-07-07T13:15:03Z")

</div>

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.
