Nilearn colorbar title

I haven’t seen anyone ask, though I admit I may have missed it somewhere. Is there a way to specify a title for colorbar (e.g. using plot_stat_map) so that units are available (e.g. z-score). I know I can put it in the overall plot title, but that’s not always desirable.

In my experience, you can play with the ticklabels (e.g. adding units), but I’m not aware of colorbar title. You should be able to do anything that the matplotlib API allows.
HTH,
Bertrand

for most plotting functions, you can access and tweak the colorbar via the private attribute _cbar

from nilearn.datasets import load_sample_motor_activation_image
from nilearn.plotting import plot_stat_map, show
from matplotlib import pyplot as plt

stat_map = load_sample_motor_activation_image()
fig = plot_stat_map(stat_map, figure=plt.figure(figsize=(6, 6)))

# set title
fig._cbar.ax.set_title("FOO")

show()

Great. Thanks @Remi-Gau.

1 Like