I want to implement a conditional colormap depending on levels (i.e. value of z) similar to a traffic light (green=go, yellow=slow down, red=stop) in a 3D bar plot of an array of z values. The colormap should display green when 0<z=<0.2; yellow when 0<z=<0.4 and red when z>0.4. However, it plots the value linearly between red, yellow and green; what I need is the full color when z value is in the corresponding color range. I tried to work it out with caxis but it did not work. Someone knows how to input conditions for each level of the map? This is the code for the plot and the colormap.
b=bar3((DGP),1); for k = 1:length(b) zdata = b(k).ZData; b(k).CData = zdata; end view(0,90) shading interp DGPmap = [1,0,0;1,1,0;0,1,0]; % red; yellow; green;
colormap(DGPmap);
Thank you for the help!
Best Answer