How to set the unequal interval colorbar for colormap!
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
ren ren
el 28 de Mayo de 2019
Comentada: ren ren
el 28 de Mayo de 2019
Hello, how to set the colorbar as the picture shows?
The colorbar is not the equal interval!
Thanks!

0 comentarios
Respuesta aceptada
Bjorn Gustavsson
el 28 de Mayo de 2019
The QD-way I'd try first would be to make up a suitable transform of the data to map from being linear between 25 and 25 to what is desired. Something like this:
y = 1:19; % This defines the output of the data-transform
x = [-25:5:-5,-4:4,5:5:25]; % this is the input
d = 3*peaks(123);
dtr = d;
dtr(:) = interp1(x,y,d(:),'pchip'); % here we transform the data - only for displaying...
subplot(1,2,1)
imagesc(d)
colorbar
subplot(1,2,2)
imagesc(dtr)
cblh = colorbar; % and here we have to pay the price of being cunning/lazy
set(cblh,'ytick',1:19) % and set ticks and ticklabels manually
set(cblh,'ytick',1:19,'yticklabel',num2str(x'))
HTH
3 comentarios
Bjorn Gustavsson
el 28 de Mayo de 2019
That mapping simply takes the values of my d and puts values between -25 and -20 to values between 1 and 2, values between -20 and -15 will end up between 2 and 3 in the output - and so on. Therefore values between 0 and 1 will end up between 9 and 10 in the output (10 and 11, somewhere in the middle) and will occupy the same fraction of the range of output data as values between -25 and -20. If you have a book on image processing at hand you could look up histogram equalization, this is the same idea.
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!