Plots by nilearn (plotting.plot_img_on_surf) appear too bright using Spyder IDE

Hi,

I have the problem that the plots or Figures created via nilearn’s plotting.plot_img_on_surf appear way too bright when plotting with the Spyder IDE. It looks as if the gamma of the picture is way too high.

I know that one can adjust the brightness of the images via darkness=value,, where a higher or lower value decreases and increases the plot’s brightness, respectively. However, that does not solve the problem. While the brightness slightly changes, especially noticeable in the white subcortical areas of the brain, the “background gamma” brightness remains way too high, no matter what values I choose.

I did not face this problem on my old laptop where I used the standard Python IDE. I am on a Mac, using miniconda with Sypder IDE.

Is this a bug or compatibility problem between nilearn and the Spyder IDE? Is there a way to fix this problem? Any changes within the Spyder IDE options did not affect or solve the plot brightness. This problem does not appear for any other plots or figures, but only in this specific case using plotting.plot_img_on_surf.

I attach an image that shows (1) the plotted image on my old laptop using Python IDE (normal brightness or gamma of the picture) and (2) the other image shows the current but way too bright image with my new setup.

Here is my code:

# Data
nifti = nilearn.image.load_img(f"/volumes...")

# Cortical mesh
mesh = datasets.fetch_surf_fsaverage(mesh=plot,
                                     data_dir="/users/...")

# Plot
vmax = 0.55
fig, axes = plotting.plot_img_on_surf(stat_map=nifti,
                                      surf_mesh=mesh,
                                      threshold=0.001,
                                      views=["lateral", "medial"],
                                      hemispheres=["left", "right"],
                                      inflate=False,
                                      bg_on_data=True,
                                      colorbar=True,
                                      vmax=vmax,
                                      darkness=0.5,
                                      antialiasing=True,
                                      cmap=range_cmap)

Thanks for any help or info, as I really cannot find the source of the problem.

after the next nilearn release, the scale_bg_map option may be able to help:

also the parameter alpha will be added so that you can control the transparency of the stat map and the background will show through:

in the meanwhile I’m not sure where the difference you see comes from;

  • what nilearn version are you using on each machine?
  • what matplotlib backend are you using on each machine?

Hi Jerome and thank you for your response.

I am using the most up-to-date versions of nilearn and matplotlib on both Macbooks, the previous one being a 2013 Intel one, the newer one a 2021 M1 Pro. My assumption is that the problem of a way too high “gamma” or “background” light of the brain’s cortical surface is somehow related to the Spyder IDE, as the problem does not occur in the standard Python IDE installation that I use on my old macbook.

I am looking forward to the nilearn updates, maybe I can solve my problem with nilearn’s new features for plotting that you mentioned.

I see – and do you see the problem if you run the script by invoking python directly from the command-line, without using spyder? also it could be due to different matplotlib backends, you could check what is the output of

>>> import matplotlib
>>> matplotlib.get_backend()

on both machines