MATLAB Answers

Reverse the colorbar axis

262 views (last 30 days)
Claire on 30 Apr 2012
Commented: prio on 1 Apr 2018
I have a contourf plot, which I plotted across the range 2 to -2. I have edited the colormap to get it to move between green and brown.
I don't want to change the colormap, or the values that are associated with each color. All I want to do is essentially flip the colorbar, so that -2 is at the top, and 2 is at the bottom.
All the solutions I have found so far only flip the colors, which is not what I want to do.
I'm basically looking for an equivalent function to: set(gcf,'YDir','reverse') but for the colorbar.
I'd appreciate any help I can get. Cheers, Claire.

  1 Comment

Cody Webb
Cody Webb on 25 Oct 2015
How did you flip just the colors and not the axis?

Sign in to comment.

Accepted Answer

Geoff on 30 Apr 2012
The call to colorbar returns a handle. There's lots of options in there to set, and you'll find the one you wanted, too.
h = colorbar;
set( h, 'YDir', 'reverse' );


Show 1 older comment
debojit on 10 Feb 2014
awesomeeeeeeeee!!! I really needed that. Thanks
Germano Scarabelli
Germano Scarabelli on 8 Jan 2015
thanks! I spent a lot of time trying to reverse it!
prio on 1 Apr 2018
Thanks a lot!

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Translated by