필터 지우기
필터 지우기

Place text on a subplot: Any way to autowrap?

조회 수: 9 (최근 30일)
FM
FM 2022년 7월 13일
편집: FM 2022년 7월 15일
I used the "text" command to place text onto a subplot. I have to insert line breaks manually, which I would like to avoid.
The "annotate" command seemed like a solution (https://www.mathworks.com/matlabcentral/answers/218675-is-it-possible-to-create-textbox-with-fixed-width-on-a-plot). However, the 4 position parameters are relative to the entire figure rather than the pair of axes in a subplot.
Is there something like "annotate", but for a pair of axes?
  댓글 수: 5
Adam Danz
Adam Danz 2022년 7월 15일
You must be using regular axes (position == innerposition). With uiaxes, position==outerposition. I'm not suggesting you change to uiaxes, the problem won't change.
About the figure resize, you could also set the "resize" property of the figure to off.
I wonder if you're drawing the annotation textbox too early, before the axes have fully rendered or before you apply the long yticklabels. Does the problem happen if you wait to apply the annotation box? If you provide a minimal working example it would be easier to see what's going on.
FM
FM 2022년 7월 15일
편집: FM 2022년 7월 15일
I think the problem might be the long labels. Here is a minimum working example.
close all
set(gcf,'Position',[100 100 289 274])
subplot(2,2,1)
barh( rand(1,5) );
set(gca,YTickLabel=["One One" "Two Two" "Three Three" "Four Four" "Five Five"]);
annotation('textbox' , ...
get(gca,"InnerPosition") , ...
String='The quick brown fox jump over the lazy dogs.', ...
FitBoxToText='off');
For this example, the annotation box starts to track the axes size properly when the figure width is about 500+ points/pixels.
AFTERNOTE: You may be right about the rendering of the annotation before the labels are rendered. I placed "pause(5)" before the annotation command, and the text box becomes properly sized.
I need to guess at the shortest pause needed and hard code this in. I don't suppose that there is a way to tell Matlab to wait for the completion of one statement before proceeding with the next? Or does the figure simply receive a signal to place labels and, while it is busying doing so, it immediately returns control back to the invoking script?

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

답변 (0개)

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by