How to specify the colors within a colorbar
78 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Caroline Whyatt
el 24 de Abr. de 2017
Comentada: Caroline Whyatt
el 25 de Abr. de 2017
Hello all,
I am having problems setting the face color of my colorbar.
I have a range of data points color coded based on an underlying variable (example below is based on points ranging between Red - Yellow). While I can specify the value limits of the color bar, I am having trouble specifying the exact face color to be displayed on the color bar.
I have tried to directly edit within the color bar editor - but to no avail.
Any help would be much appreciated.

2 comentarios
Image Analyst
el 24 de Abr. de 2017
You've not given us much to go on. So just make up an N by 3 array of values in the range 0-1 and use the colormap() and colorbar functions. You might also use caxis(). A more descriptive question may get you a better answer.
Respuesta aceptada
David Goodmanson
el 25 de Abr. de 2017
Editada: David Goodmanson
el 25 de Abr. de 2017
Hi Carolyn, All you need do is change the colormap line to
colormap(sort(Color, 'descend'));
but make sure that you have cleared your variables first. With your previous command, Matlab creates a variable named 'colormap' and you do not want that.
The forgoing method works, but you get a pretty ugly colorbar with four sections of constant color. For a nicer colorbar you can make a more continuous version of the colormap, such as
x=[1,2,3,4];
y=[5,6,7,8];
sz = 100;
N = 64; % or whatever
Color1 = [ones(N,1),(N-1:-1:0)'/(N-1),zeros(N,1)];
colormap(Color1)
s=scatter(x,y,sz,y,'filled');
colorbar
This also gives you the opportunity to put not a matrix of rgb values into the scatter 'C' input as you did, but but rather to make C a vector of the same length as x and y. Then the collection of C vector values is mapped into the entire colormap from bottom to top. As you see, the y values were mapped to colors in the code above. That idea may not apply directly in your case with the circular plot, but you can make a C vector with appropriate values that map into the colormap.
Más respuestas (0)
Ver también
Categorías
Más información sobre Color and Styling en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
