Hello @FranziMNE,
many journals specify the expected width (entire page or single-column) and resolution of the figures you need to submit.
You can use Matplotlib to create figures that exactly match these specifications, without too much manual fiddling.
For example, assuming you want to save a figure that’s 15 cm wide and has a resolution of 1200 dpi, you can use:
target_width_cm = 15
target_width_in = 15 / 2.54 # convert to inches
fig.set_figwidth(target_width_in)
fig.set_tight_layout(True)
fig.savefig(
'/tmp/myfig.tiff',
dpi=1200,
pil_kwargs={
'compression': 'tiff_lzw' # drastically reduces file size
}
)
The resulting image will still have a bit of padding around it, which you can remove by doing something like:
fig.savefig(
'/tmp/myfig.tiff',
dpi=1200,
bbox_inches='tight',
pad_inches=0,
pil_kwargs={
'compression': 'tiff_lzw' # drastically reduces file size
}
)
However, in this case, the resulting width won’t exactly match 15 cm at 1200 dpi anymore, unfortunately.
Here’s a complete working example based on one of the MNE tutorials:
# %%
import os.path as op
import numpy as np
import mne
from mne.time_frequency import tfr_morlet, psd_multitaper, psd_welch
from mne.datasets import somato
data_path = somato.data_path()
subject = '01'
task = 'somato'
raw_fname = op.join(data_path, 'sub-{}'.format(subject), 'meg',
'sub-{}_task-{}_meg.fif'.format(subject, task))
raw = mne.io.read_raw_fif(raw_fname)
raw.crop(120, 360).load_data().resample(200)
events = mne.find_events(raw, stim_channel='STI 014')
picks = mne.pick_types(raw.info, meg='grad', eeg=False, eog=True, stim=False)
event_id, tmin, tmax = 1, -1., 3.
baseline = (None, 0)
epochs = mne.Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=baseline, reject=dict(grad=4000e-13, eog=350e-6),
preload=True)
psds, freqs = psd_multitaper(epochs, fmin=2, fmax=40, n_jobs=1)
psds = 10 * np.log10(psds) # convert to dB
psds_mean = psds.mean(0).mean(0)
psds_std = psds.mean(0).std(0)
freqs = np.logspace(*np.log10([6, 35]), num=8)
n_cycles = freqs / 2. # different number of cycle per frequency
power, itc = tfr_morlet(
epochs, freqs=freqs, n_cycles=n_cycles, use_fft=True,
return_itc=True, decim=3, n_jobs=-1
)
# %%
figs = power.plot([82], baseline=(-0.5, 0), mode='logratio', title=power.ch_names[82])
fig = figs[0]
# %%
target_width_cm = 15
target_width_in = 15 / 2.54
fig.set_figwidth(target_width_in)
fig.set_tight_layout(True)
fig
# %%
fig.savefig(
'/tmp/myfig.tiff',
dpi=1200,
# bbox_inches='tight',
# pad_inches=0,
pil_kwargs={
'compression': 'tiff_lzw'
}
)
I hope this helps you a bit!
Best wishes,
Richard