Move colorbar closer to figure?
46 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a colorbar with no title that I need to move closer to my figure to reduce padding/white space between the figure and the colorbar. I've tried to experiment with position using the colorbar position properties but I'm striking out. Below is a snippet of code:
How can I adjust the colorbar toward the figure (in this case from bottom toward the top)?
hcb=colorbar('SouthOutside');
% Set the number of colorbar ticks and length of tick marks
set(hcb,'YTick',[-6:0.25:6],'TickLength',[0.01]);
% Label tick marks but only label every other tick mark
set(hcb,'YTickLabel',{'-6';'';'';'';'-5';'';'';'';'-4';'';'';'';'-3';'';'';'';'-2';'';'';'';'-1';'';'';'';'0';'';'';'';'1';'';'';'';'2';'';'';'';'3';'';'';'';'4';'';'';'';'5';'';'';'';'6'});
hcb.Ruler.TickLabelRotation=0;
0 comentarios
Respuestas (1)
Voss
el 15 de Mzo. de 2024
hcb=colorbar('SouthOutside');
% Set the number of colorbar ticks and length of tick marks
set(hcb,'YTick',[-6:0.25:6],'TickLength',[0.01]);
% Label tick marks but only label every other tick mark
set(hcb,'YTickLabel',{'-6';'';'';'';'-5';'';'';'';'-4';'';'';'';'-3';'';'';'';'-2';'';'';'';'-1';'';'';'';'0';'';'';'';'1';'';'';'';'2';'';'';'';'3';'';'';'';'4';'';'';'';'5';'';'';'';'6'});
hcb.Ruler.TickLabelRotation=0;
% move colorbar up slightly:
drawnow
hcb.Position(2) = hcb.Position(2)+0.01;
7 comentarios
Voss
el 18 de Mzo. de 2024
What figure properties are you setting? Only Position?
figure('position', [0, 0, 730, 1300]);
caxis([-6 6]); % R2019b
hcb=colorbar('SouthOutside');
% Set the number of colorbar ticks and length of tick marks
set(hcb,'YTick',[-6:0.25:6],'TickLength',[0.01]);
% Label tick marks but only label every other tick mark
set(hcb,'YTickLabel',{'-6';'';'';'';'-5';'';'';'';'-4';'';'';'';'-3';'';'';'';'-2';'';'';'';'-1';'';'';'';'0';'';'';'';'1';'';'';'';'2';'';'';'';'3';'';'';'';'4';'';'';'';'5';'';'';'';'6'});
hcb.Ruler.TickLabelRotation=0;
% store axes Position:
axPos = get(gca,'Position');
% move colorbar up slightly:
hcb.Position(2) = hcb.Position(2)+0.01; % back to 0.01 for a figure of this height
% restore axes Position:
set(gca,'Position',axPos);
Voss
el 18 de Mzo. de 2024
Note that I changed the colorbar position adjustment from 0.03 to 0.01 for the tall figure. Colorbar units are 'normalized' by default.
Ver también
Categorías
Más información sobre Grid Lines, Tick Values, and Labels en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!