how to flip color in colorbar without changing the values?

106 views (last 30 days)
colorbar
caxis([1 100]);
i want to make 100 = blue and 1 = red
thank you so much..
  2 Comments
John Manalo
John Manalo on 12 May 2015
figure(1)
colorbar
caxis([10 100]);
fig=figure(1)
colorbar
mycmap = get(fig,'Colormap')
set(fig,'Colormap',flipud(mycmap))
this script does not work on large values like caxis([10 500]);
Walter Roberson
Walter Roberson on 12 May 2015
I am not sure what you are saying. You appear to be attempting to alter caxis when there is existing graphics and expecting the existing graphics to stay the same. caxis changes the entire axis at the same time.
However, when you use colorbar() a new axis is created in versions before R2014b, and without doing a lot of checking I cannot be sure that it is paying attention to changes in the caxis of the original axes. I seem to recall stepping through it all years ago and finding that it set up a listener on the original axis properties. But what it used to do isn't too important if you are running R2014b or later as colorbar() now creates colorbar objects, and I have no idea how those are programmed.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 12 May 2015
oldcmap = colormap;
colormap( flipud(oldcmap) );

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!