Question

In GNU Octave you can make a picture where different colors represent different values in a matrix. You can also add a colorbar, which shows what color corresponds to what value.

Is it possible to somehow add units to the values shown in the colorbar? Instead of saying “0.36” it would say “0.36 V/nm”? I know this is possible in Matlab, but I can’t figure out how to do it in Octave. Any good workarounds?

I assume someone here will mention that I should use matplotlib instead (that usually happens). How would you accomplish the same thing with that?

Was it helpful?

Solution

The matplotlib answer (using pylab) is

imshow(random((20,20)))
colorbar(format='%.2f V/nm')

In Octave it seems that the following works (but I'm no Octave expert so maybe there's a better way):

c=colorbar();
labels = {};
for v=get(c,'ytick'), labels{end+1} = sprintf('%.2f V/nm',v); end
set(c,'yticklabel',labels);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top