mangoez
(Po)
1
I’ve been trying to follow the instructions to pass through an axes to plot_joint
fig, ax = plt.subplots(figsize=(15,8))
grating1.plot_joint(times=times, ts_args = {"axes": ax}, topomap_args = {"axes": ax})
plt.show()
But this comes with an error: TypeError: ‘AxesSubplot’ object is not iterable
So I try creating list of axes objects and it complains about them being lists?!:
fig, (ax1, ax2) = plt.subplots(1,2,figsize=(15,8))
grating1.plot_joint(times=times, ts_args = {"axes": [ax1,ax2]}, topomap_args = {"axes": [ax1,ax2]})
plt.show()
ValueError: axes must be a list or numpy array of matplotlib axes objects while one of the list elements is <class ‘list’>.
I tried putting square brackets around ax to make it a list and it complains about it being lists. Can’t seem to win.
Can someone just tell me how on earth I can change the figure size or show me an example please?
richard
(Richard Höchenberger)
2
It’s difficult because plot_joint()
works with many, many axes:
# %%
import matplotlib.pyplot as plt
import mne
sample_dir = mne.datasets.sample.data_path()
sample_fname = sample_dir / 'MEG' / 'sample' / 'sample_audvis_raw.fif'
raw = mne.io.read_raw_fif(sample_fname)
raw.crop(tmax=60)
events = mne.find_events(raw, stim_channel='STI 014')
epochs = mne.Epochs(raw, events=events)
evoked = epochs.average()
evoked.pick_types(eeg=True)
fig = evoked.plot_joint()
print(len(fig.axes))
prints:
7
Add to that the fact that you get one figure per sensor type if you have multiple sensor types, … it’s really complex.
I’d suggest taking a step back and plotting the traces and topoplot (including its colorbar) separately. This should give you a starting point:
# %%
import matplotlib.pyplot as plt
import mne
sample_dir = mne.datasets.sample.data_path()
sample_fname = sample_dir / 'MEG' / 'sample' / 'sample_audvis_raw.fif'
raw = mne.io.read_raw_fif(sample_fname)
raw.crop(tmax=60)
events = mne.find_events(raw, stim_channel='STI 014')
epochs = mne.Epochs(raw, events=events)
evoked = epochs.average()
evoked.pick_types(eeg=True)
fig, axs = plt.subplots(1, 3, figsize=(15,8))
evoked.plot(axes=axs[0], spatial_colors=True)
evoked.plot_topomap(times=0.2, axes=axs[1:3])
But if it’s really just about the figure size, as suggested in the title, you can simply do something like:
fig = evoked.plot_joint()
fig.set_size_inches((15, 8))
Best wishes,
Richard
2 Likes