How to adjust the view of colorbar to be the same as contourf

조회 수: 1 (최근 30일)
logo cuit
logo cuit 2021년 7월 21일
편집: Jonas 2021년 7월 21일
Hello everyone, I tried many ways to adjust the view of the colorbar to the same view of the fill image, but failed.
%%
x = 100*rand(100,100);
contourf(x,'Linestyle','none');
set(gca,'view',([5,30]));
axis([0 100 0 100 0 1]);
c = colorbar;
%%
it looks like the position of the colorbar in the figure below,is there any way to solve it?

채택된 답변

Chunru
Chunru 2021년 7월 21일
You may want to create the colorbar yourself that attached to the data as follows:
n = 50;
x = 100*rand(n,n);
% Add the custom colorbar by extending the data
% gaps of 2 | color bars with width if 2
x = [x nan(n, 2) repmat(linspace(1,100,n)', [1 4])];
contourf(x,'Linestyle','none');
set(gca,'view',([5,30]));
box off
axis off
  댓글 수: 2
Chunru
Chunru 2021년 7월 21일
If you want the perspetive projection:
n = 50;
x = 100*rand(n,n);
% Add the custom colorbar by extending the data
% gaps of 2 | color bars with width if 2
x = [x nan(n, 2) repmat(linspace(1,100,n)', [1 4])];
contourf(x,'Linestyle','none');
%set(gca,'view',([5,30]));
camproj('perspective')
view([0 -10 5]);
%axis([0 100 0 100 0 1]);
box off
axis off
logo cuit
logo cuit 2021년 7월 21일
Thank you very much. This idea can help me solve it

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jonas
Jonas 2021년 7월 21일
편집: Jonas 2021년 7월 21일
try that adding the colors to the image and add artificial labels using text
close all;
x = 100*rand(100,100);
contourf(x,'Linestyle','none');
c = colorbar;
climits=c.Limits; % get limits of original colorbar
x=[x repmat(linspace(climits(1), climits(2),100)',[1 10])]; % add colorbar to image itself
contourf(x,'Linestyle','none'); % plot again
axis([0 110 0 110 0 1]); % extend view to 110 to see the artificial colorbar of width 10
view([5 30]); yticklabels([]); % remove ylabels so we can add our colorbar labels at the position % alternatively you can also edit the yticklabels and inserrt the values from the text() function below
labelPos=0:10:100;
labelVal=linspace(climits(1),climits(2),numel(labelPos));
for labelNr=1:numel(labelPos)
text(115,labelPos(labelNr),0,num2str(round(labelVal(labelNr)))); % add text labels near colorbar
end
xticks(0:10:100); % to prevent the 110 tick value which is not part of the original image

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by