# Plotting event-related dynamics for specific frequency bands

**URL:** <https://mne.discourse.group/t/plotting-event-related-dynamics-for-specific-frequency-bands/8176>\
**Category:** Support & Discussions\
**Created:** [January 18, 2024, 5:29pm UTC](https://mne.discourse.group/t/plotting-event-related-dynamics-for-specific-frequency-bands/8176 "2024-01-18T17:29:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![FedeGiova](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/fedegiova/32/3330_2.png) [@FedeGiova](https://mne.discourse.group/u/FedeGiova)\
**Post date:** [January 18, 2024, 5:29pm UTC](https://mne.discourse.group/t/plotting-event-related-dynamics-for-specific-frequency-bands/8176/1 "2024-01-18T17:29:18Z")

</div>

Hi!

I’m run some experiments with a Biosemi ActiveTwo with 64 channels. Now I’m following [this tutorial](https://mne.tools/stable/auto_examples/time_frequency/time_frequency_global_field_power.html#sphx-glr-auto-examples-time-frequency-time-frequency-global-field-power-py) for plotting the activity of each specific frequency band of a specific channel (Fpz)

My problem is that when make the plot, the scale in the y-axis seems wrong. The curves of each frequency band seems too little, like if the y scale was too big. One thing that calls my attention is that at beggining and the end of each plot (-500 and 3000ms), I see a rise in the curves. Maybe there’s something wrong with the baseline? Maybe the first and the last time point is not scaled?

I tried changing the x-axis limits but it doesn’t help. I also thought of changing the y axis scale by hand. But I’m sure there must be a more straight forward way of solving it. Or maybe I’m missing something.

Here’s the plot

 ![output](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/4/471e0b2e0fd888728be597ded95c629fe26986a1.png)

Here’s the plot zoomed in the beggining of the epoch

 ![output](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/3/3e1beceab4dbb633ed167e181257febe76999c92.png)

And here is the code:

```python
import matplotlib.pyplot as plt
from mne.stats import bootstrap_confidence_interval
from mne.baseline import rescale

# Helper function for plotting spread
def stat_fun(x):
    """Return sum of squares."""
    return np.sum(x**2, axis=0)

# Plot
fig, axes = plt.subplots(5, 1, figsize=(10, 7), sharex=True, sharey=True)
colors = plt.colormaps["winter_r"](np.linspace(0, 1, 5))
for ((freq_name, fmin, fmax), average), color, ax in zip(
    frequency_map, colors, axes.ravel()[::-1]
):
    times = average.times * 1e3 
    gfp = np.sum(average.data**2, axis=0)
    gfp = mne.baseline.rescale(gfp, times, baseline=(-500, 0))
    ax.plot(times, gfp, label=freq_name, color=color, linewidth=2.5)
    ax.axhline(0, linestyle="--", color="grey", linewidth=2)
    ci_low, ci_up = bootstrap_confidence_interval(
        average.data, random_state=0, stat_fun=stat_fun
    )
    ci_low = rescale(ci_low, average.times, baseline=(None, 0))
    ci_up = rescale(ci_up, average.times, baseline=(None, 0))
    ax.fill_between(times, gfp + ci_up, gfp - ci_low, color=color, alpha=0.3)
    ax.grid(True)
    ax.set_ylabel("GFP")
    ax.annotate(
        "%s (%d-%dHz)" % (freq_name, fmin, fmax),
        xy=(0.95, 0.8),
        horizontalalignment="right",
        xycoords="axes fraction",
    )
    ax.set_xlim(-500, 3000)
    #ax.set_ylim(1e-8*-0.1, 1e-8*0.5)

axes.ravel()[-1].set_xlabel("Time [ms]")

fig

```

Thanks!

---

<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:** [January 19, 2024, 7:14am UTC](https://mne.discourse.group/t/plotting-event-related-dynamics-for-specific-frequency-bands/8176/2 "2024-01-19T07:14:56Z")

</div>

I think it would be good to confirm that the raw EEG signals are correctly scaled and look like valid EEG (e.g. no large artifacts etc.). A PSD would also be helpful to make sure that your t/f analysis is based on decent EEG.
