Hello MNE community,
I am writing because I am struggling to save a 3D connectivity plot as a JPG or PNG file. I found this thread on the forum: How to save plot_sensors_connectivity()? - #6 by AMumin.
I am using PyCharm, and although the plot is generated correctly, the script seems to keep running, and I am unable to save the image.
This is the code I am using:
import numpy as np
import pyvista
from mne_connectivity.viz import plot_sensors_connectivity
# Imposta PyVista
np.bool = bool # Compatibilità per numpy
pyvista.global_theme.notebook = False
pyvista.start_xvfb() # Avvia un server di rendering headless
# Genera il plot
connectivity_fig = plot_sensors_connectivity(epoch.info, conn.get_data(output="dense")[:, :, 0])
fig.set_size_inches(desired_width, desired_height)
fig.savefig('my_figure.png')
This is a screenshot of what I see on my notebook:
Actually the process is described differently in this comment:
You should do something along the liens of
# %%
# Do the actual plotting
connectivity_fig = plot_sensors_connectivity(
epochs.info,
con.get_data(output='dense')[:, :, 0]
)
# Take a screenshot of the 3D scene
screenshot = connectivity_fig.plotter.screenshot()
# The screenshot is just a NumPy array, so we can display it via imshow()
# and then save it to a file.
fig, ax = plt.subplots(figsize=(10, 10))
ax.imshow(screenshot, origin='upper')
ax.set_axis_off() # Disable axis labels and ticks
fig.tight_layout()
fig.savefig('connectivity.png', dpi=150)
Not sure if this will fix the issue you described above, though!
You may want to consider not using the Notebook 3d backend by first running: