Nilearn: Is it possible using view_surf to render a non symmetric surface data with negative values with bg?

Hi, I have a question regarding plotting.view_surf.
I have a surface map that contains data for part of the brain. The data is both negative and positive ranging from -0.2 to 0.5. Is it possible to render this data as html page, while showing the bg_map where there is no data?

Hi @tsahia

Could you take a look at this example from the gallery:

Especially section shows how to use view_surf with texture (with positive and negative values) and background.

Let me know if this helps!

Hi @NicolasGensollen
Thank you for your answer.
The example you give has two differences from my case.

  1. The data in the example is symmetric, my data is not
  2. The threshold i need to give is not percentile but a value. I can set any value (for example 0, or 1) to all the vertices that i do not have data it.

The problem is that view_surf expects the data to be symmetric around 0 and check abs(threshold), which is not my case.


@tsahia yes, view_surf enforces a symmetric colormap for statistical maps having both negative and positive values. In the example, the data isn’t symmetric though:

import numpy as np
from nilearn import datasets, surface, plotting

fsaverage = datasets.fetch_surf_fsaverage()
motor_images = datasets.fetch_neurovault_motor_task()
stat_img = motor_images.images[0]
texture = surface.vol_to_surf(stat_img, fsaverage.pial_right)
print(f"texture min = {np.min(texture)}\ntexture max = {np.max(texture)}")
texture min = -3.795675683286116
texture max = 7.94134521484375

But you can still specify the threshold as a value, and a value for vmax:

from nilearn import plotting
view = plotting.view_surf(fsaverage.infl_right, texture,
                          threshold=1.3, vmax=2,



I think i am not explaining the situation clear enough
In your example all values between -1.3 and 1.3 and also above 2 will not be displayed.
Using the example you give i could set all vertices that i want bg to be displayed to hold the value 0, and use thershold=0.1. The problem would be that the color map (and color bar) would span from -7.9 to 7.9 and not from -3.79 to +7.9 as the data is, and this is due to the symmetry.
In essence the fact that the abs(threshold) is checked vs the abs(data) does not allow to show color maps that spans only the data when the data has negative values and is not symmetric.

Unless there is a way to do it that i do not see.

Thank You


unfortunately ATM I don’t think it is possible to force view_img to use an asymmetric colormap when the map contains negative values – the colormap will be centered on 0; eg with cold_hot colormap negative values will be blue and positive values will be red

Thanks for the explanations @tsahia.
As @jeromedockes said, there is currently no way to use use asymmetric colormaps through view_img. And I believe this is consistent across functions plotting surface statistical maps in Nilearn (like plot_surf_stat_map for example) since they call the same function colorscale:

Thank you, this is what i thought, i was just wondering if i missed something.
I changed the code such that it doesn’t have to be symmetrical, and i wonder why it is this way in the first place.

in most cases we want to distinguish negative and positive activations

It doesn’t mean it has to be symmetrical