Avoid topoplot being plotted

I want to save topoplot in an array instead of being displayed.
This is what i am doing

mne.viz.plot_topomap(pwr[:,j].ravel(),data.info,show=False,res=128);
ar=saveasarray()

saveasarray is a custom function which is working
issue is that, even show=False, still its plotting topoplots

Hello @talhaanwarch and welcome to the forum!

If you’re running the code in an interactive Python window, this can very well be the case. The solution to this is usually to assign the returned figure to a variable, e.g.,

fig = mne.viz.plot_topomap(...)
ar = saveasarray()

Best wishes,
Richard

i even tried that, but this did not worked

Can you please share the output of

import mne
mne.sys_info()

Platform: Linux-5.11.0-34-generic-x86_64-with-glibc2.29
Python: 3.8.10 (default, Jun 2 2021, 10:49:15) [GCC 9.4.0]
Executable: /home/talha/venv/bin/python3
CPU: x86_64: 24 cores
Memory: 31.4 GB

mne: 0.23.4
numpy: 1.21.2 {blas=openblas, lapack=openblas}
scipy: 1.7.1
matplotlib: 3.4.3 {backend=module://matplotlib_inline.backend_inline}

sklearn: 0.24.2
numba: Not found
nibabel: Not found
nilearn: Not found
dipy: Not found
cupy: Not found
pandas: 1.3.2
mayavi: Not found
pyvista: Not found
vtk: Not found

Thanks!

How do you run your code? If you do it line-by-line in an interactive Jupyter or IPython window, even the fig = ... assignment won’t suffice. Probably what would help is appending a del fig to that very line:

fig = mne.viz.plot_topomap(...); del fig

(untested)

i am using jupyter notebook, and del fig, did not worked

what i was thinking if we define it this way

if show:
    plt_show(show)

Hi, I have also the same problem. I solved saving the topoplot and load in the following lines. I suggest, to use interp2d function of scipy library but the problem is that in this way you interpolate function on plane and not on sphere, so the result is similar but not the same