Question: subplot axes label cut off (activepositionproperty problem?)

조회 수: 37 (최근 30일)
Paul B
Paul B 2012년 2월 21일
댓글: Sebastian Henn 2021년 8월 4일
Hi! I want to make a subplot such that two plots are side by side. The resulting figure needs to be small enough to fit in my document, and in the eps format. However, when I try to resize the figure past a certain size, the axes x labels are cut off like so :
this only happens when you resize it small enough. Also, it doesn't happen with the 'plot' command, I can resize as much as i like and the axes labels are maintained in the figure. My understanding is that activepositionproperty governs this sort of thing, and that it should be set to 'outerposition', but I've tried forcing that and it doesn't have any effect. Also, it doesn't seem to matter if you manually set the papersize and paperposition and then export, or whether you change the figure size using WYSIWYG on screen and then exporting. Would be grateful for any ideas to work around or fix this problem! I'm sure it didn't used to happen on earlier versions of matlab
  댓글 수: 3
Paul B
Paul B 2012년 2월 21일
Sorry Jan, I did put the version in the question but it doesn't seem to display the answer I gave. It's version R2010a but I don't have access to a later version to test it.
To answer your question, this code is a test to recreate the problem...
ax1 = subplot(121);
plot(1:10);
set(ax1,'ActivePositionProperty','outerposition');
xlabel('xlabel')
ylabel('ylabel')
ax2 = subplot(122);
plot(1:10);
xlabel('xlabel')
ylabel('ylabel')
set(ax2,'ActivePositionProperty','outerposition');
...and then try resizing your figure a bit on screen, if you go small enough the x label is cut off. I tried setting paperpositionmode to 'auto' and File -> save as eps, obviously it just prints what is on the screen so the x label is cut off. I also tried setting..
set(gcf,'PaperPositionMode','manual','PaperUnits','inches','PaperPosition',[0 0 6 2])
print -deps figure.eps
...and this still cuts off the x label. Making it 6 by 4 just about includes the x label, but then the graphs are stretched beyond what I want. I'm curious if this happens to anyone else !
Paul B
Paul B 2012년 2월 21일
By the way I've managed to test it with matlab r2007b, and i can confirm that there is no problem with the xlabel no matter how small you size the figure. So it seems to me this is a problem with how recent versions of matlab handle the activepositionproperty within the subplot environment, unless I'm doing something stupid!

댓글을 달려면 로그인하십시오.

채택된 답변

Jason P
Jason P 2012년 2월 28일
I have been having the same problem but just got around it by "hacking" the axis position for each of the subplots:
v = get(gca,'Position');
set(gca,'Position',[v(1) v(2)*1.5 v(3:4)])
and you can adjust the values v(2) and v(4) to be whatever looks best for you.
  댓글 수: 1
Paul B
Paul B 2012년 4월 21일
Ok thanks Jason! This is a good workaround but I still think the original problem is a bug. Will get round to reporting it one day!

댓글을 달려면 로그인하십시오.

추가 답변 (4개)

William Thielicke
William Thielicke 2020년 11월 24일
So this bug still hasn't been fixed...? After 8.5 years...?

Shep Bryan
Shep Bryan 2021년 1월 29일
I have found a pretty decent work around. When you make your xlabel, add an extra blank line like this:
xlabel({'my label', ''})
That way the extra line gets cut off, but the real label is preserved.

Petr Chernikov
Petr Chernikov 2021년 4월 21일
@matlab-team, don't worry, we will wait another 10 years.

Yavor Dobrev
Yavor Dobrev 2021년 8월 3일
Since R2020a there is a property, which solves this problem. Setting PositionConstraint to outerposition solved it for me. See https://de.mathworks.com/help/matlab/creating_plots/automatic-axes-resize.html

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by