colorbar tick distance to axes and label position
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Star Strider
il 22 Dic 2023
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.
Risposte (1)
Image Analyst
il 22 Dic 2023
- 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 Commenti
Image Analyst
il 22 Dic 2023
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).
Vedere anche
Categorie
Scopri di più su Colorbar in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!