0

I would like to plot multiple PSD obtained with plot_psd() from MNE python.

I tried the following code

import matplotlib.gridspec as gridspec

gs = gridspec.GridSpec(3,1)
plt.figure()
ax = plt.axes()

# First plot
ax1 = fig.add_subplot(gs[0]
raw_egi.plot_psd(ax=ax1)

ax2=fig.add_subplot(gs[1]
raw_ws_ds_hp_lp.plot_psd(ax=ax2)

ax3= fig.add_subplot(gs[2]
raw_ws_ds_hp_lp_nf.plot_psd(ax=ax3)

plt.show()

It tells me that I have an invalid syntax.

The following code is working but all plots are superimposed

import matplotlib.gridspec as gridspec

gs = gridspec.GridSpec(3,1)
plt.figure()
ax = plt.axes()

# First plot
raw_egi.plot_psd(ax=ax)

raw_ws_ds_hp_lp.plot_psd(ax=ax)

raw_ws_ds_hp_lp_nf.plot_psd(ax=ax)

plt.show()

Could you tell me ho to plot these 3 figures without superimposing but vertically (one by row). Bellow you will find the figure with the working code (i.e. 3 superimposed plots) Thanks for your help enter image description here

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
fredooms
  • 123
  • 8
  • Does this answer your question? [How to plot in multiple subplots](https://stackoverflow.com/questions/31726643/how-to-plot-in-multiple-subplots) – Trenton McKinney Oct 05 '21 at 14:23

1 Answers1

0

Here is how I solve the question for 2 plots

import matplotlib.pyplot as plt

fig, ax = plt.subplots(2)

raw_bp.plot_psd(ax=ax[0], show=False)
raw_bp_nf.plot_psd(ax=ax[1], show=False)

ax[0].set_title('PSD before filtering')
ax[1].set_title('PSD after filtering')
ax[1].set_xlabel('Frequency (Hz)')
fig.set_tight_layout(True)
plt.show()
fredooms
  • 123
  • 8