Can adjust raw.plot figure size using rc settings in v .24

  • MNE-Python version: 0.24
  • Python 3.9
  • operating system: Mac Big Sur 11.3.1

Until I installed v0.24, I was able to adjust the size of my raw plot by setting the values in rcParams as in this simple example. (Note: I’m not using the new mne-qt-browser here.)

import mne
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [18,10]
raw = mne.io.read_raw_edf('file.edf',preload=True)
raw.plot)

Now, it appears that changing the values has no effect on my raw plot size. I know matplotlib recognizes the updated figure size values because I can print out the values using

fig = plt.gcf()
size = fig.get_size_inches()
print(size)

to get [18,10]. Also I can adjust the plot size for a simple non-mne plot.

rcParams is defined by matplotlib, and will only be respected by the matplotlib backend. PyQtGraph is an alternative backend to matplotlib and doesn’t honor matplotlib settings.

I think I’m missing something. What exactly can I do to adjust the raw plot size?

Well, I’m not certain, but I think what you’re missing is the idea that PyQtGraph is one way of making plots, and matplotlib is another way of making plots, and changing rcParams will only affect plots made with matplotlib. If you’re asking MNE-Python to use the PyQtGraph backend for the raw data browser, rcParams will never even be looked at. (Additionally, rcParams are only defaults; any plot where figsize is explicitly set in the plotting function will ignore rcParams, though that’s not really the issue here).

Regarding specifically the raw data browser (and not other MNE-Python figures), MNE-Python additionally has its own configuration value, MNE_BROWSE_RAW_SIZE which can be manually set with mne.set_config() and which is automatically updated each time you close a raw data browser window. So it should work to make a raw browser plot, drag the window corners to the size you want, close it, and next time you open a raw browser plot it should default to the adjusted size. Or, make an appropriate call to set_config() before you plot.

So I’m not asking MNE-Python to create my plot using PyQtGraph. I was under the impression that raw.plot was constructing my data browser using matplotlib. This is why, to adjust the size of my plot, I simply set plt.rcParams["figure.figsize"] = [18,10]. This worked for me until I updated to MNE .24.

I did follow your second suggestion in terms of setting the configuration value of MNE_BROWSE_RAW_SIZE. This worked, but I also had to set matplotlib.use('Qt5Agg') in order to get a graph having the desired height. I don’t understand why that is though.

Here’s what ultimately seemed to work.

import mne
import matplotlib
matplotlib.use('Qt5Agg')
from matplotlib import pyplot as plt

raw = mne.io.read_raw_edf('myfile.edf',preload=True)
mne.set_config('MNE_BROWSE_RAW_SIZE','16,8')  
# Above values obtained after much experimentation. 
# Even a small change to the pair 14,6 resulted in an almost-square plot. 

raw.plot(block=True)

ahhh, OK. sorry I misread your initial post, where you said “I’m not using the new mne-qt-browser here” (emphasis added). I can confirm the behavior: if MNE_BROWSE_RAW_SIZE is not set, raw.plot() seems to be unaffected by plt.rcParams. As I’m typing this I remember why: we set a hard minimum of 8x8 inches in the raw.plot() code, because without it we had people constantly getting raw plots that matplotlib set to the default size of 640x480 pixels, which caused those “bottom margin cannot be greater than top” errors.

TL;DR: use mne.set_config() to control plot size, plt.rcParams won’t work anymore and we probably won’t change that.

Thank you so much for your help!