필터 지우기
필터 지우기

Is it possible to create textbox with fixed width on a plot?

조회 수: 9 (최근 30일)
Mr M.
Mr M. 2015년 5월 26일
편집: FM 2022년 7월 13일
I would like to add paragraph with fixed width as a caption to the figure, but I don't want to set by hand the linebreaks!

답변 (1개)

Ashish Gudla
Ashish Gudla 2015년 5월 27일
You can use the annotation textbox with the 'FitBoxToText' property set to 'off'. This will wrap the text to fit the width of the text box.
Ex:
>>figure; % new figure window
>>plot(1:10);
>>annotation('textbox', [0.2,0.4,0.5,0.1],...
'String', 'This is a test string.This is a test string.This is a test string.This is a test string.',...
'FitBoxToText','off');
You can refer to other properties here:
  댓글 수: 1
FM
FM 2022년 7월 13일
편집: FM 2022년 7월 13일
The 4 position parameters seem to relative to the entire figure rather than an pair of axes in a subplot. Can this be done within a subplot?
AFTERNOTE: With help from [https://www.mathworks.com/matlabcentral/answers/356708-how-to-position-a-annotation-in-subplot-southeast], I supplied "get(gca,'Position')" as the "dim" name/value parameter:
annotation('textbox',get(gca,'Position'),String="The quick brown fox",FitBoxToText='off')
Unfortunately, the text box's left edge overlaps with the y-axis labels!
A work-around that doesn't involve manual customization of the "Position" based on Figure size and number of subplots would be welcome. Thanks!
P.S. I currently finagle the position by manually resizing the text box, issuing "get(gco,'Position'), then editing the "annotation" command to use this position. Ideally this would not be necessary.

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

카테고리

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