Reverse the colorbar axis

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 comentario

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

Iniciar sesión para comentar.

 Respuesta aceptada

Geoff
Geoff el 30 de Abr. de 2012

9 votos

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 comentarios

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

Iniciar sesión para comentar.

Más respuestas (1)

Ryan Caveney
Ryan Caveney el 14 de Feb. de 2025

0 votos

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

Categorías

Más información sobre Color and Styling en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 30 de Abr. de 2012

Respondida:

el 14 de Feb. de 2025

Community Treasure Hunt

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

Start Hunting!

Translated by