colorbar tick distance to axes and label position
7 次查看(过去 30 天)
显示 更早的评论
Hi,
I have the following figure generated from MATLAB2023b
by the following code
fig = figure;
fig.Position = [0 900 600 500];
% code for creating the contour
% ...
% ...
pbaspect([18 8 1]);
clim([-0.5 1]);
cbar = colorbar;
cbar.Location = 'north';
cbar.AxisLocation = 'in';
cbar.Ruler.TickLabelFormat = 25;
cbar.Position = [0.5; 0.91; 0.32; 0.03]; % controls the colorbar position
cbar.Label.Interpreter = 'latex';
cbar.Label.String = '$\langle u\rangle$';
cbar.Label.Rotation = 0;
cbar.Label.Position = [-1 -2]; % controls the label position
cbar.Label.Interpreter = 'latex';
cbar.Label.FontSize = 25;
My question is:
- how to obtain the distance/relative position from the colorbar ticks to the axes (i.e., the red arrow and green arrow)? The command cbar.Position can only manipulate the position of the colorbar itself; it doesn't include the size of the tick labels.
- what's the meaning of the second number in cbar.Label.Position (i.e., cbar.Label.Position(2)), indicated by the blue arrow? For the same value here (which is -2), the position of the label with respect to the colorbar will change if the fig size is changed as well. So it seems it is somehow dependent on the figure size.
3 个评论
Star Strider
2023-12-22
My impression is that you defined the Position of the colorbar, so it should be set as you defined it. The Label position relates to the colorbar itself, since the Label is simply a text object. All those positions are somehow encoded in the figure properties, however exactly how (and how to get or set them) appears not to be documented.
回答(1 个)
Image Analyst
2023-12-22
- You can get the position property of both cbar handle, and the axes.
ax = gca
axesPosition = as.Position
2. The Position property has these 4 meanings: [xLeft, yTop, width, height].
If that doesn't get what you want, look at findobj and start looking at what the "children" of the axes represent.
2 个评论
Image Analyst
2023-12-22
OK, never mind then. I guess they're using a different definition of Position here than they do in most other places then (e.g. the rectangle function).
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Colorbar 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!