Problem with set(gca, 'Position', [...]);
이전 댓글 표시
Hi there,
I've recently moved from v2013a Matlab to v2020a (an overdue change driven by my institute). I've got a plotting script that I was working on at v2013a just the other day but which now behaves strangely at v2020a.
It has two subplots, and right at the end, repositions the second to match the first's horizonal position.
figure(1); clf;
subplot (2,1,1);
pcolor (tval, yval, t1); shading flat;
ylabel (ystr); title (titstr1);
cb = colorbar; pos1 = get(gca, 'Position');
subplot (2,1,2);
plot (tval, t2, 'k-');
ylabel (ystr);
xlabel ('Time [year]'); title (titstr2);
pos2 = get(gca, 'Position'); pos2(1) = pos1(1); pos2(3) = pos1(3); set (gca, 'Position', pos2);
What should happen is that the second subplot's horizontal length is shortened to match the first subplot's reduced length (which stems from it having a colorbar). I do this so that the two time-series are aligned on the plot.
And this script works fine at v2013a. But at v2020a, when I cut and paste the above into the command window (my preferred mode of working), it does everything except for the repositioning. Even though the command is right there. Even more strangely, if I then manually paste the final statement ...
set (gca, 'Position', pos2);
... into the command window after it's failed to do what I ask, it then does it correctly. I can think of no good reason why this is, and my attempts to "trick" Matlab (e.g. by duplicating the set statement, or by assigning a named handle to the subplot) have all failed. It needs me to separately paste in the final command for it to properly execute it. Which is completely impractical for this particular script because the plotting is meant to be part of a loop over many plots.
Over the (many) years I've used Matlab, I'm familiar with the ordering of commands being important to the final result, but this failure to do what it's told, and then doing what it's told (but forcing me to ask it in a clunky manual fashion) is new to me.
What am I missing about how v2020a works?
Best regards,
Andrew.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!