Want to make changes to the colorbar
조회 수: 20 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Montree
2015년 1월 2일
Use 'YTicklable' such as...
colorbars('YTicklabel',{'0','1'})
See more detail on matlab help.
추가 답변 (1개)
Image Analyst
2015년 1월 3일
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
Image Analyst
2015년 1월 4일
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
2015년 1월 5일
"A"'s "Answer" moved here to be a comment since it's not an "Answer" to the original question.
That works. Thanks!
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!