resize and define the position of the colorbar

103 visualizaciones (últimos 30 días)
Haythem Zouabi
Haythem Zouabi el 12 de Nov. de 2020
Comentada: Cris LaPierre el 12 de Nov. de 2020
Hello,
I need to resize and define the position of the colorbar.
This is my code:
ax3 = subplot(2,3,2);
ibg2 = imagesc(scene);
axis off
hold on
iim2 = imagesc(im,'XData',[16 466],'YData',[104 484]);
caxis([0 3])
iim2.AlphaData = 0.75*ones(size(im));
iim2.AlphaData(isnan(im)) = 0;
colorbar
colormap parula
caxis([0 3])
cb = colorbar;
set(cb,'position',[.10 .1 .1 .1])
This is the graph i get :
I need to place the color bar in the blue box (see figure)?
Thanks,

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 12 de Nov. de 2020
Your position argument is relative to the entire figure, not the plot. Adjust it to be what you want it to be.
Also, including target axes might help.
scene = imread('peppers.png');
im = imread("cameraman.tif");
ax3 = subplot(2,3,2);
ibg2 = imagesc(scene);
axis off
hold on
iim2 = imagesc(ax3,im,'XData',[16 466],'YData',[104 484]);
hold off
iim2.AlphaData = 0.75*ones(size(im));
iim2.AlphaData(isnan(im)) = 0;
colormap parula
caxis([0 3])
cb = colorbar(ax3);
cb.Position = [.45 .6 .05 .1];
  2 comentarios
Haythem Zouabi
Haythem Zouabi el 12 de Nov. de 2020
Is there any way to automatise the position of the colorbar with different images placed at different position?
Note that i always need to place the colorbar at the bottom-left corner of a given image.
Thanks,
Cris LaPierre
Cris LaPierre el 12 de Nov. de 2020
I had some success with the 'Location' setting.
scene = imread('peppers.png');
im = imread("cameraman.tif");
subplot(2,3,2);
imagesc(scene);
axis off
cb = colorbar('west');
cb.Position = cb.Position .* [1 1 1 .5];
subplot(2,3,4);
imagesc(im);
axis off
cb = colorbar('west');
cb.Position = cb.Position .* [1 1 1 .5];

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by