scripting figure position commands

I want toeliminate the wasted space at the edge of the figure window. This below code works fine for simple plots, but if I have a colorbar or legend that resides outside the main plot area, then it ends up being cropped off the figure. A similar situation is encountered when using subplots, only to a much worse degree. Here is the code I am using:
bounds = get(gca,'tightinset'); set(gca,'position',[bounds(1) bounds(2) 1-bounds(1)-bounds(3) 1-bounds(2)-bounds(4)]);
It seems that the problem is that other items such as a legend or colorbar are really a different set of axes, so they are not included in the space calculations. Any suggestions on ways to improve this?

답변 (2개)

Jan
Jan 2011년 8월 18일

0 개 추천

Perhaps you want to change the DefaultAxesPosition of the FIGURE:
figure;
axes;
colorbar;
figure('DefaultAxesPosition', [0.1, 0.1, 0.85, 0.85]);
axes;
colorbar;

댓글 수: 1

Michael
Michael 2011년 9월 2일
If every figure would be the same layout, then that might work, but I need something that can work on arbitrary layouts.

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

Daniel Shub
Daniel Shub 2011년 8월 18일

0 개 추천

You might want to look through the FEX

댓글 수: 1

Michael
Michael 2011년 9월 2일
I looked at panel based on your recommendation and it looks to be extremely powerful, but I had problems getting it to behave properly on my machine (callbacks that wouldn't work, etc.). Furthermore, it is a big change from the way I have been doing things. I would prefer to just have a quick script that could be applied to figures I have already created using simple (or complex) plot commands. There may be things of value that I could extract from the panel code and use by themselves, but I haven't had the time yet to try to find them.

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

카테고리

도움말 센터File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

질문:

2011년 8월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by