How to set the unequal interval colorbar for colormap!

29 Ansichten (letzte 30 Tage)
ren ren
ren ren am 28 Mai 2019
Kommentiert: ren ren am 28 Mai 2019
Hello, how to set the colorbar as the picture shows?
The colorbar is not the equal interval!
Thanks!
QQ截图20190528140347.jpg

Akzeptierte Antwort

Bjorn Gustavsson
Bjorn Gustavsson am 28 Mai 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 Kommentare
Bjorn Gustavsson
Bjorn Gustavsson am 28 Mai 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.
ren ren
ren ren am 28 Mai 2019
Great answer! Solve the problem perfect!
Thanks very much!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by