# How to plot EpochsTFR images?

**URL:** <https://mne.discourse.group/t/how-to-plot-epochstfr-images/3070>\
**Category:** Support & Discussions\
**Tags:** time-frequency, visualization\
**Created:** [April 30, 2021, 5:56am UTC](https://mne.discourse.group/t/how-to-plot-epochstfr-images/3070 "2021-04-30T05:56:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xiaofang](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/xiaofang/32/265_2.png) [@Xiaofang](https://mne.discourse.group/u/Xiaofang)\
**Post date:** [April 30, 2021, 5:56am UTC](https://mne.discourse.group/t/how-to-plot-epochstfr-images/3070/1 "2021-04-30T05:56:28Z")

</div>

- MNE-Python version: 0.22.0
- operating system: win10  
I want to plot the time-frequency diagram of each trail of EpochsTFR, but I don’t want to use the plt.contourf method, because the image obtained is a bit redundant, as shown below:  
 ![image](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/9444748d5c49ca1b57bfbc13524096633c342c7c.png)  
AverageTFR provides the plot method, and the time-frequency graph obtained is as follows, which is very beautiful, so I was thinking, can EpochTFR also provide the plot function?  
 ![image](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/fdfbc57c7a388b93791474ce822538ccde27fa86.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:** [October 19, 2021, 6:43am UTC](https://mne.discourse.group/t/how-to-plot-epochstfr-images/3070/2 "2021-10-19T06:43:01Z")

</div>

There is no `plot` method for `EpochsTFR`, but if you want something similar to what we do in `AverageTFR.plot`, you could try [`matplotlib.pyplot.imshow`](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.imshow.html) (there’s also [`matplotlib.axes.Axes.imshow`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.imshow.html) if you prefer this API).

---

<div class="post-metadata">

**Author:** ![mmagnuski](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mmagnuski/32/153_2.png) [@mmagnuski](https://mne.discourse.group/u/mmagnuski)\
**Post date:** [October 19, 2021, 12:35pm UTC](https://mne.discourse.group/t/how-to-plot-epochstfr-images/3070/3 "2021-10-19T12:35:05Z")

</div>

Another way is to select the epoch you want to visualise, then average (which does not change the data, but the object is now `AverageTFR` and has the `.plot()` method) and use the `.plot()` method:

```python
tfr[0].average().plot(picks='Oz')

```

---

<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:** [October 19, 2021, 1:15pm UTC](https://mne.discourse.group/t/how-to-plot-epochstfr-images/3070/4 "2021-10-19T13:15:46Z")

</div>

This seems to indicate that we **should** have a respective plotting function for `EpochsTFR`…

---

<div class="post-metadata">

**Author:** ![mmagnuski](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mmagnuski/32/153_2.png) [@mmagnuski](https://mne.discourse.group/u/mmagnuski)\
**Post date:** [October 19, 2021, 2:43pm UTC](https://mne.discourse.group/t/how-to-plot-epochstfr-images/3070/5 "2021-10-19T14:43:01Z")

</div>

> [@richard](#):
>
> to indicate that we **should** have a respective plotting function for `EpochsTFR` …

I would make `EpochsTFR.plot()` raise an error and tell the user to select the epochs via indexing, average and plot 😄  
I must say I like the index, average and plot way - it is explicit. Especially if one is selecting multiple trials - a condition for example. But I agree that for plotting single trials, the `.average()` step is counter-intuitive.  
One rather simple way to avoid the `.average()` for single epochs would be to return `AverageTFR` when indexing selects a single epoch. It would not be very elegant though. 🙂

---

<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:** [October 19, 2021, 3:25pm UTC](https://mne.discourse.group/t/how-to-plot-epochstfr-images/3070/6 "2021-10-19T15:25:51Z")

</div>

> [@mmagnuski](#):
>
> I would make `EpochsTFR.plot()` raise an error and tell the user to select the epochs via indexing, average and plot 😄

But we don’t do that for Epochs either so IMHO that’s inconsistent

---

<div class="post-metadata">

**Author:** ![mmagnuski](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mmagnuski/32/153_2.png) [@mmagnuski](https://mne.discourse.group/u/mmagnuski)\
**Post date:** [October 19, 2021, 9:24pm UTC](https://mne.discourse.group/t/how-to-plot-epochstfr-images/3070/7 "2021-10-19T21:24:32Z")

</div>

@richard Yes, I wasn’t fully serious. 🙂 However, I’m not sure what should be the default - plotting a tfr for every epoch would not make sense if one does `tfr_epochs.plot()`. Maybe something reasonably good would be to show the first epoch by default and allow navigating through the tfr epochs interactively (so something similar to what `epochs.plot()` does).
