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

1 visualización (últimos 30 días)
logo cuit
logo cuit el 21 de Jul. de 2021
Editada: Jonas el 21 de Jul. de 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?

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (1)

Jonas
Jonas el 21 de Jul. de 2021
Editada: Jonas el 21 de Jul. de 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

Categorías

Más información sobre Colormaps en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by