Place text on a subplot: Any way to autowrap?

3 ビュー (過去 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 Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by