Place text on a subplot: Any way to autowrap?

3 visualizaciones (últimos 30 días)
FM
FM el 13 de Jul. de 2022
Editada: FM el 15 de Jul. de 2022
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 comentarios
Adam Danz
Adam Danz el 15 de Jul. de 2022
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 el 15 de Jul. de 2022
Editada: FM el 15 de Jul. de 2022
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?

Iniciar sesión para comentar.

Respuestas (0)

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by