필터 지우기
필터 지우기

colorbar tick distance to axes and label position

조회 수: 8 (최근 30일)
Sijie Huang
Sijie Huang 2023년 12월 22일
댓글: Star Strider 2023년 12월 22일
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:
  1. 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.
  2. 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
Sijie Huang
Sijie Huang 2023년 12월 22일
@Star Strider Then is it possible to get the axes positions of the colorbar object? So I can adjust my label position accordingly.
Star Strider
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
Image Analyst 2023년 12월 22일
  1. 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
Sijie Huang
Sijie Huang 2023년 12월 22일
편집: Sijie Huang 2023년 12월 22일
  1. the cbar.Position does not provide or include the information about the size/position of the tick labels
  2. the cbar.Label.Position only contains three values, rather than the conventional [xLeft, yTop, width, height]
Image Analyst
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 CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by