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

2 ビュー (過去 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 Center および File ExchangeColormaps についてさらに検索

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by