views:

431

answers:

1

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?

+1  A: 

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);
Jouni K. Seppänen
I didn't get your Octave code to work (possibly version 3.0 is too old), but since pylab enables very Octave-like code, I could easily port my code to use that instead.
pafcu
I have version 3.2.2 so it could well be a version problem. Does get(c,'yticklabel') return anything on your version? Can you use set(c,'yticklabel') to make tick labels by hand?
Jouni K. Seppänen