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

2 Ansichten (letzte 30 Tage)
logo cuit
logo cuit am 21 Jul. 2021
Bearbeitet: Jonas am 21 Jul. 2021
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?

Akzeptierte Antwort

Chunru
Chunru am 21 Jul. 2021
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 Kommentare
Chunru
Chunru am 21 Jul. 2021
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 am 21 Jul. 2021
Thank you very much. This idea can help me solve it

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Jonas
Jonas am 21 Jul. 2021
Bearbeitet: Jonas am 21 Jul. 2021
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

Kategorien

Mehr zu Colormaps finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by