editing the JET colormap

42 visualizaciones (últimos 30 días)
Hans123
Hans123 el 25 de Jun. de 2020
Comentada: Hans123 el 29 de Jun. de 2020
I want to edit the jet colormap such that it reflects that values of 0 are shown in white, I followed the below code and the following figure was obtained
a=colormap(jet)
n = length(a)/2;
a(n,:)=[1 1 1]; %replaces the midpoint with a white line
...
%plot...
%colorbar...
I found out the midpoint of the colormap does not necessarily mean the midpoint I am looking for - i.e. 0. my question is how can I tweak the above code to give me a white line when the value of the colorbar = 0?

Respuesta aceptada

Bjorn Gustavsson
Bjorn Gustavsson el 25 de Jun. de 2020
You should be able to do something like this:
imagesc(peaks(123))
cx = caxis;
n_colors = 128
cmp = jet(n_colors);
colorbar
colormap(cmp)
idx0 = round(1 + (n_colors-1)/diff(cx)*(0-cx(1))); % closest index to zero-level of current caxis
cmp(idx0,:) = 1;
colormap(cmp)
HTH
  5 comentarios
Bjorn Gustavsson
Bjorn Gustavsson el 26 de Jun. de 2020
OK step by step.
cx = caxis;
Is just getting the intensity-limits of the colour-scale, you get a 1 x 2 array out with [cmin, cmax].
The line
idx0 = round(1 + (n_colors-1)/diff(cx)*(0-cx(1)));
Is just the equation for a straight line on the form
if you see the limits of the intensity-range as and and the end-indices of the colormap (1 and n_colors) as and . Then the "fractional index" closest to zero should be what we get when plugging 0 into . But we have to round that.
cmp(idx0,:) = 1;
We simply set all 3 components of the colormap-array on row idx0 to one (white). You can set it to any [r g b] as long as all three are between 0 and 1.
Then we set the colormap of the current figure to that colormap
Hans123
Hans123 el 29 de Jun. de 2020
Thank you, I really appreciate your help!

Iniciar sesión para comentar.

Más respuestas (1)

Steven Lord
Steven Lord el 25 de Jun. de 2020
You should probably read through this documentation page and the pages listed in the "Related Topics" section on that page. It talks about how MATLAB maps your data onto the colormap.
If you want a white line around where your data is zero, I wouldn't necessarily adjust the colormap for that. I'd probably plot the surface with all my data then add one contour or contour3 at level 0. The LineSpec input to contour or contour3 lets you make the line white and the LineWidth name-value pair argument lets you make the line thinner or thicker if you need it to stand out more clearly.

Categorías

Más información sobre Blue 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!

Translated by