Nilearn plot_glass_brain: how to change color?

Hi all,

I was wondering if anyone could help me with the color option for nilearn plot_glass_brain.
the default option gives me a continuous color (image below) but I want discrete colors.

thanks in advance!

I haven’t tested this out for nilearn specifically, but you should be able to create a discrete colormap with matplotlib and apply it to your image.

To create the discrete colormap:

import matplotlib.cm

discrete_cmap = matplotlib.cm.get_cmap("hot_r", 5)

In this case, the discrete colormap is saved to the variable discrete_cmap. The hot_r is the same colormap you’ve shown in the image, and 5 sets the number of discrete values. You can also change the colourmap or the number of discrete colours.

To apply this to the plot_glass_brain, you can do use the cmap option:

plot_glass_brain(cluster, colorbar=True, title="cluster 5", display_mode="lyrz", cmap=discrete_cmap)

thanks!! works perfectly!