Imagesc Color Assignment of Values
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi I am currently trying to create a colormap for the function imagesc(); Currently my code looks like the following:
caxis manual
my_map=[0 0 0;1 1 1;1 0 1;1 0 0];
x=[0:100];
imagesc(x)
colormap(my_map)
colorbar
As of right now it will map values of 0:25 to white, 25:50 red and so forth. Is there any method I could use to change the assignment of values for the colors. Example: assigning values of 0:5 to white 6:80 black.
Thank you in advance.
0 comentarios
Respuestas (2)
yanqi liu
el 5 de En. de 2022
clc; clear all; close all;
% 0:25 to white, 25:50 red and so forth.
figure;
caxis manual
my_map=[0 0 0;1 1 1;1 0 1;1 0 0];
x=[0:100];
imagesc(x)
colormap(my_map)
colorbar
% 0:5 to white 6:80 black.
figure;
caxis manual
my_map=[repmat([1 1 1], length(0:5), 1)
repmat([0 0 0], length(6:80), 1)
repmat([1 0 0], length(81:100), 1)];
x=[0:100];
imagesc(x)
colormap(my_map)
colorbar
Walter Roberson
el 4 de En. de 2022
NO.
Values below the first caxis value are always assigned the lowest color in the color map.
Values above the second caxis value are always assigned the highest color in the color map.
In-between, the ratio: (value - caxis(1))/(caxis(2)-caxis(1)) is calculated, and that gives you the linear portion of the way through the colormap that is used.
There is no way to say to use a particular colormap entry for a particular range of values, and a different colormap entry for a different range of values.
What you can do is create a colormap with 27 entries. Assign the same white color to the first two. Assign black to the remaining 25 entries. The span of values is 81, so the first three values (0, 1, 2) would use the "first" white slot, the second three values (3, 4, 5) would use the "second" white slot, and all other values would use some other slot that would happen to hold black.
But it is typically easier instead,
bin = discretize(x, [0 5 80 inf])
imagesc(bin)
colormap(my_map)
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!

