Using the GUI, see Color bar in slice viewers
And programmatically, see Show scalar bar programmatically