editing the JET colormap
44 views (last 30 days)
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
n = length(a)/2;
a(n,:)=[1 1 1]; %replaces the midpoint with a white line
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?
Bjorn Gustavsson on 25 Jun 2020
You should be able to do something like this:
cx = caxis;
n_colors = 128
cmp = jet(n_colors);
idx0 = round(1 + (n_colors-1)/diff(cx)*(0-cx(1))); % closest index to zero-level of current caxis
cmp(idx0,:) = 1;
More Answers (1)
Steven Lord on 25 Jun 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.