matlab - Different colours for maximum and minimum of data -
i have data normalised beween 0 , 1 continuous values inbetween. possible make colour map highlight 1 particular value? in case, want max value of 1 custom defined colour , rest use normal colour map. have tried editing colour map appending on desired colour plot uses colour values close 1 well. suggestions appreciated.
function cplotdemo clc; close all; clear all; data = peaks; data = (data - min(data(:))) / ( max(data(:)) - min(data(:)) ); figure, contourf(data) colormap(jet2) colorbar function j = jet2(m) if nargin < 1 m = size(get(gcf,'colormap'),1); end n = ceil(m/4); u = [(1:1:n)/n ones(1,n-1) (n:-1:1)/n]'; g = ceil(n/2) - (mod(m,4)==1) + (1:length(u))'; r = g + n; b = g - n; g(g>m) = []; r(r>m) = []; b(b<1) = []; j = zeros(m+1,3); j(r,1) = u(1:length(r)); j(g,2) = u(1:length(g)); j(b,3) = u(end-length(b)+1:end); j(end,:)=[(256/2)/255,(0)/255,(256/2)/255];
i think happening because of way contourf works. example posted there should on value equal 1 , 1 want use custom colour with.
here example of creating custom colormap highlights single level value. in case peak color black. can adjust level
highlight value in surface , not peak.
% ================================================== % define data % -------------------------------------------------- [x,y] = meshgrid(-2:0.1:2, -2:0.1:2); z = exp(-(x.^2+y.^2)); peak = max(z(:)); % ================================================== % define level highlight , color % -------------------------------------------------- level = z(20,20); color = [0,0,0]; cm = hsv; nrows = size(cm,1); row = round(nrows * level / peak); cm(row,:) = color; % ================================================== % plot surface custom colormap % -------------------------------------------------- surf(x, y, z); colormap(cm);
here output figure
note, if want highlight particular pixel in surface , not value can define color matrix using surf. here relevant part docs:
surf(x,y,z,c) uses c define color. matlab® performs linear transformation on data obtain colors current colormap.
Comments
Post a Comment