colormap I need have the color of the 0 explicit

6 Ansichten (letzte 30 Tage)
Vasco
Vasco am 12 Sep. 2023
Bearbeitet: Dyuman Joshi am 12 Sep. 2023
I need to make a colormap where i need the value of 0 is a different color of the rest i want it to be grey [0.5 0.5 0.5] taking into account the values I impose for the color bar
I need to take into account the clev
figure(1);
axis equal;
clev = -0.5:0.01:0.5;
[x,y] = meshgrid(lon,lat);
contourf(x, y, lwe', clev, 'LineStyle', 'none', 'Fill', 'on');
xlabel('Longitude');
ylabel('Latitude');
clim([min(clev), max(clev)]);
colormap(winter(length(clev)-1));
colorbar('eastoutside');
c = colorbar;
c.Label.String = 'Valor em metros (m)';
title(strcat('GRACE-', tm));

Antworten (1)

Walter Roberson
Walter Roberson am 12 Sep. 2023
This cannot be done through colormap.
Colormaps use slots of equal width. The color stored in a slot is not required to be unique. It would be perfectly valid, for example, to create a colormap of 101 entries in which the top 50 and the bottom 50 were all the same color and the middle was a different color. But the middle would still occupy a range of values -- with a large-enough color map it might not be a big range of values, but it will never be a single value such as exactly 0 (with, for example, 1e-20 being the next color)
That said, if you happen to have a situation where the values are quantized, and the levels are symmetric, then you can do things such as
nlev = length(clev);
cmap = winter(nlev);
cmap((nlev+1)/2,:) = [0.5 0.5 0.5];
colormap(cmap);

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by