Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to adjust colorbar range in a matlab plot

Status
Not open for further replies.

geo2006

Geotechnical
Jan 5, 2006
22
CL
Hi everyone,

new to Matlab here. I have a n x m matrix with values in the range 0.0-3.0 aprox. I want to make a plot using only 2 colors: red if value < 1 and green otherwise. I used imagesc with colormap ([1 0 0; 0 1 0]). The problem is that the colorbar divides the range from 0 to 1.5 (red) and 1.5 to 3.0 (green). I suppose it's easy, but I can't found how to change the colorbar limits, in order to get 0.0 to 1.0 = red, and 1.0 to 3.0 = green. Any help?

Thank you in advance.
FGS
 
Replies continue below

Recommended for you

Thanks, Greg. I haven't solved my problem yet, just trying alternative solutions like your suggestion. Seems a good idea, i'll try it.

(BTW, sorry for my delay in the response)

FGS

 
Try this: If the N x M is huge, you save a lot of overhead by just altering the structure contents.

x = [0 1 2 3;1 2 3 0;2 3 0 1;3 0 1 2] % example user array
map = [1 0 0; 0 1 0]; % The red & green primaries wanted

S= imagesc(x) % nice pretty colors, regardless...

CD = get(S,'CData') % Don't wipe the original matrix. Extract the plot data.

CD(find(CD <= 1)) = 0 % user paint scheme. 0 is 1st color
CD(find(CD > 1)) = 1 % 2nd color

set(S,'CData',CD) % 2 Pac Secure, but wrong colors.

colormap(map) % Merry Christmas !
%when you are happy with the results:

colormap % restore the original colors.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top