필터 지우기
필터 지우기

Fit figure size to textbox

조회 수: 4 (최근 30일)
Ondrej
Ondrej 2012년 3월 10일
Is there some way to fit the figure size to the textbox? Example:
I have a = annotation(... 'textbox','Position',[0.1482 0.7333 0.17 0.16],... 'FitHeightToText','on',... 'String','Example');
which makes a textbox in a figure. I would like to fit the size of the figure to this textbox. Is it possible? Thanks.

채택된 답변

Jacob Halbrooks
Jacob Halbrooks 2012년 3월 12일
You could compute your desired figure Position from the annotation and then set it, but you'll have to manage the Units consistently and reset the annotation's normalized position at the end. For example, something like this:
a = annotation('textbox','Position',[0.1482 0.7333 0.17 0.16], 'FitHeightToText','on','String','Example');
set(a,'Units','pixels');
aPos = get(a,'Position');
fPos = get(gcf,'Position');
fPos(3:4)=aPos(3:4);
set(gcf,'Position',fPos);
set(a,'Units','norm','Position',[0 0 1 1])
When possible though, it's better to create the container to the desired size first and then create its children using normalized position to fill up the container.
  댓글 수: 1
Ondrej
Ondrej 2012년 3월 15일
Thank you Jacob. Great.
I only slightly modified your code, but it works perfectly:
a = annotation('textbox','Position',[0.1482 0.7333 0.17 0.16], 'FitBoxToText','on','String','Example');
set(a,'Units','pixels');
aPos = get(a,'Position');
fPos = get(gcf,'Position');
fPos(3:4)=aPos(3:4);
set(gcf,'Position',fPos,'Paperposition','auto');
set(a,'Units','norm','Position',[0 0 1 1])

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by