center axis+labels inside figure
이전 댓글 표시
Hello,
I am trying to standaryse different figures, same total size,same font, same fontsize, linewidth etc.
the issue I am facing is that when I add the y and x labels, sometimes the labels are outside of the figure (they get cropped) as I fix the position of the figure. one partial solution I found looking around is to get the axis position and then translate it by a factor. (for example 10% for y and 35% for x) by:
axes=gca
v = get(axes,'Position');
set(axes,'Position',[v(1)*1.35 v(2)*1.1 v(3:4)])
what I was looking for would be something where I could centrate the complete block, axes+thicks+x&y labels in the midel of the figure.
would this be possible?
thanks.
답변 (1개)
The OuterPosition property gives you the box around the axes that includes the ticks and labels (and title):
ax = axes;
ax.OuterPosition=[.2 .2 .6 .6];
title('TITLE')
xlabel({'xlabel' 'has' 'multiple' 'rows'})
ylabel('ylabel')
annotation('rectangle',ax.OuterPosition,'Color','r')
annotation('rectangle',ax.Position,'Color','g')
Another useful property is PositionConstraint (note that on older releases, including 2018b, this was called ActivePositionProperty). When PositionConstraint is set to OuterPosition, and you add a title/xlabel/ylabel the OuterPosition will be held constant (the default behavior), so the InnerPosition (aka Position) will shrink. When the PositionConstraint is set to InnerPosition, the InnerPosition will be helpd constant, so the OuterPosition will grow. This can be a bit confusing to think about, but not so bad if you experiment a bit:
figure
ax1=axes('Position',[.1 .3 .3 .3], 'PositionConstraint', 'OuterPosition');
ax2=axes('Position',[.6 .3 .3 .3], 'PositionConstraint', 'InnerPosition');
title(ax1, 'Outer')
xlabel(ax1, {'xlabel' 'has' 'multiple' 'rows'})
ylabel(ax1, 'ylabel')
title(ax2, 'Inner')
xlabel(ax2, {'xlabel' 'has' 'multiple' 'rows'})
ylabel(ax2, 'ylabel')
Some helpful documentation at: https://www.mathworks.com/help/matlab/creating_plots/automatic-axes-resize.html
댓글 수: 1
franco otaola
2021년 11월 3일
편집: franco otaola
2021년 11월 3일
카테고리
도움말 센터 및 File Exchange에서 Axis Labels에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

