Hi guys,
I have a simply surface below which gets printed with a colorbar. I want to make some minor adjustments to the colorbar. Since my graph is a very 'binary' graph (either 1 or 0), I want my colorbar to only show '0' and '1'. I don't want it to show all the decimal values between 1 and 0.
I then want the colorbar's 1 to show a certain text ("values are > 0.5") and the 0 to show ("vales are < 0.5")
Hope this makes sense. Thanks very much!
x = [-10:10];
y = [-10:10];
Eq1 = @(x,y)(x + y);
Eq2 = @(x,y)(2.*x + y);
[X,Y] = meshgrid(x,y);
Z1 = Eq1(X,Y);
Z2 = Eq2(X,Y);
D = (abs(Z2-Z1) > 0.5);
[Dr,Dc] = find(D); % Indices where D == 1
figure(1)
s1 = surf(X, Y, double(D));
colormap(winter(256))
view(0,90)
axis tight
colorbar

 Réponse acceptée

Montree
Montree le 2 Jan 2015
Use 'YTicklable' such as...
colorbars('YTicklabel',{'0','1'})
See more detail on matlab help.

1 commentaire

Thanks - I'm almost there. I just need bit more help.
1) Can I change the 'color gradient' of the color bar so that it only shows the green and the blue? And nothing in the middle?
2) How can I make changes to the text style/position/placement of the 'more' and 'less'?
x = [-10:10];
y = [-10:10];
Eq1 = @(x,y)(x + y);
Eq2 = @(x,y)(2.*x + y);
[X,Y] = meshgrid(x,y);
Z1 = Eq1(X,Y);
Z2 = Eq2(X,Y);
D = (abs(Z2-Z1) > 0.5);
[Dr,Dc] = find(D); % Indices where D == 1
figure(1)
s1 = surf(X, Y, double(D));
colormap(winter(256))
view(0,90)
axis tight
colorbar('YTick',[0 1],'YTicklabel',{'Less','More'})

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 3 Jan 2015
Are you sure you want to Accept the other answer? Because it's not giving you the colormap I think you want. What I thought you wanted is this:
x = [-10:10];
y = [-10:10];
Eq1 = @(x,y)(x + y);
Eq2 = @(x,y)(2.*x + y);
[X,Y] = meshgrid(x,y);
Z1 = Eq1(X,Y);
Z2 = Eq2(X,Y);
D = (abs(Z2-Z1) > 0.5);
[Dr,Dc] = find(D); % Indices where D == 1
s1 = surf(X, Y, double(D));
view(0,90)
axis tight
blueAndGreenColormap = [repmat([0,0,1], [128,1]) ; repmat([0,1,0], [128,1])]
colormap(blueAndGreenColormap)
colorbar
Is this really wanted instead?

8 commentaires

Yes it is! Wow. Thank you so much. What I have now is perfect thanks to you guys:
x = [-10:10];
y = [-10:10];
Eq1 = @(x,y)(x + y);
Eq2 = @(x,y)(2.*x + y);
[X,Y] = meshgrid(x,y);
Z1 = Eq1(X,Y);
Z2 = Eq2(X,Y);
D = (abs(Z2-Z1) > 0.5);
[Dr,Dc] = find(D); % Indices where D == 1
s1 = surf(X, Y, double(D));
view(0,90)
axis tight
blueAndGreenColormap = [repmat([0,0,1], [128,1]) ; repmat([0,1,0], [128,1])]
colormap(blueAndGreenColormap)
colorbar('YTick',[0 1],'YTicklabel',{'Less','More'})
Can I accept your answer? Also, how can I make changes to the "More" "Less" labels? I want to position them to be in the 'middle' of their respective colorbars. I also want to change their font style/type/etc?
You're welcome. You can adjust the location, size, and font name like this:
colorbar('YTick',[0.3 .7],'YTicklabel',{'Less','More'},...
'FontSize', 20, 'FontName', 'Courier')
Once you've Accepted one answer, you can't accept another (unless I delete the first one). But you can "Vote" for any number of answers you like to give the Answerer(s) "reputation points."
A
A le 4 Jan 2015
Thanks! I have voted you up.
A
A le 4 Jan 2015
Hi ImageAnalyst,
Quick question --> Is there a way to 'rotate' the 'Less' and 'More' text to be 90 degrees? So that the orientation of the text is vertical.
Thanks
There is a rotation property:
Rotation — Text orientation
0 (default) | scalar value in degrees
Text orientation, specified as a scalar value in degrees. The default rotation of 0 degrees makes the text horizontal. For vertical text, set this property to 90 or -90. Positive values rotate the text counterclockwise. Negative values rotate the text clockwise.
Example: 90
Example: -90
A
A le 4 Jan 2015
Modifié(e) : A le 4 Jan 2015
Thanks - but when I do this, it produces an error:
colorbar('YTick',[0.05 .95],'YTicklabel',{'Less','More'},'FontSize', 7, 'FontName', 'Calibri', 'Rotation',90)
Try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
x = [-10:10];
y = [-10:10];
Eq1 = @(x,y)(x + y);
Eq2 = @(x,y)(2.*x + y);
[X,Y] = meshgrid(x,y);
Z1 = Eq1(X,Y);
Z2 = Eq2(X,Y);
D = (abs(Z2-Z1) > 0.5);
[Dr,Dc] = find(D); % Indices where D == 1
s1 = surf(X, Y, double(D));
view(0,90)
axis tight
blueAndGreenColormap = [repmat([0,0,1], [128,1]) ; repmat([0,1,0], [128,1])]
colormap(blueAndGreenColormap)
hCB = colorbar('YTick',[0.05 .95], 'YTicklabel',[], 'FontSize', 17, 'FontName', 'Calibri')
text(13, -7, 'More Less', 'FontSize', 17, 'Rotation',90);
Image Analyst
Image Analyst le 5 Jan 2015
"A"'s "Answer" moved here to be a comment since it's not an "Answer" to the original question.
That works. Thanks!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Color and Styling dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by