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

Cody Webb
Cody Webb 2015년 10월 25일
How did you flip just the colors and not the axis?

댓글을 달려면 로그인하십시오.

 채택된 답변

Geoff
Geoff 2012년 4월 30일

9 개 추천

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' );

댓글 수: 4

Claire
Claire 2012년 4월 30일
That's exactly what I was after! I didn't know that you could use 'YDir' for the colorbar.
Thanks so much!
debojit
debojit 2014년 2월 10일
awesomeeeeeeeee!!! I really needed that. Thanks
Germano Scarabelli
Germano Scarabelli 2015년 1월 8일
thanks! I spent a lot of time trying to reverse it!
prio
prio 2018년 4월 1일
Thanks a lot!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Ryan Caveney
Ryan Caveney 2025년 2월 14일

0 개 추천

Another solution is
cm = colormap;
colormap(flipud(cm));

카테고리

도움말 센터File Exchange에서 Color and Styling에 대해 자세히 알아보기

태그

질문:

2012년 4월 30일

답변:

2025년 2월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by