Place text on a subplot: Any way to autowrap?

조회 수: 4(최근 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
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개)

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by