Move colorbar closer to figure?
47 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Voss
2024 年 3 月 15 日
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 件のコメント
Voss
2024 年 3 月 18 日
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
2024 年 3 月 18 日
Note that I changed the colorbar position adjustment from 0.03 to 0.01 for the tall figure. Colorbar units are 'normalized' by default.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!