2

This should be pretty simple I wager but I can't figure out anything on how to achieve it!

I just want my colorbar to display 1,000 instead of 1000.

Thanks!

Karl
  • 111
  • 10

2 Answers2

3

You will need to modify the TickLabels property. Below is a demostration:

figure; surf(peaks*1000);
l = colorbar;
ticks = l.Ticks;
nf = java.text.DecimalFormat;
for i = 1:numel(ticks)
    l.TickLabels{i} = char(nf.format(ticks(i)));
end 

See also How to print an integer with a thousands separator in Matlab?

enter image description here

Anthony
  • 3,595
  • 2
  • 29
  • 38
  • 1
    Truly a nicer and more easy-to-implement option than mine! – Hunter Jiang Jul 16 '18 at 02:19
  • @HunterJiang that's not only nice and easy, that's much more true also. Because he takes the real colorbar numbers, not create artificial numbers that does not relate to the graph. It makes no sense to do that – Adiel Jul 16 '18 at 07:00
  • @Adiel Agreed, and problem fixed. Thanks for pointing that out, and I must say that my aim was not creating any fake data, but using short (maybe this time curt) code to give a potential solution to his question, and we have no idea about the real data that OP has. – Hunter Jiang Jul 16 '18 at 07:31
  • 1
    @HunterJiang This is better, because the issue was the numbers vs the graph, not matter what the OP has. But IMHO it's just a little better, because that's still artificial/guess in regard to the real numbers in the graph. So at the bottom line, I can't see how that's help me... – Adiel Jul 16 '18 at 14:17
2

The code following might help,

figure
surf(peaks*1000)
c=colorbar
c.TickLabels={'-6,000','-4,000','-,2,000','0','2,000','4,000','6,000','8,000'};

which has an output like this:

enter image description here

Besides, other useful properties of colorbar is documented here.

Hunter Jiang
  • 1,300
  • 3
  • 14
  • 23