Programmatically calculate position for textbox (annotation)
Mostrar comentarios más antiguos
I have been adding textbox annotations manually with an error and trial approach.
First I place the annotation and check wether it's in the correct position, then i modify the position manually and do it over again till I am satisfied.
Is it possible to calculate the positions in programmatical way?
I have the following figure:

The code for the rectangle grid is:
f = figure('color','w','un','pix','pos',[360 150 550 300]);
a = axes('un','pix','pos',[50,30,450,231],'fonts',8,'box','on',...
'Xlim',[0,54],'Xtick',[18 36],'XtickLabel',[],'XGrid','on',...
'GridL','-','Ylim',[0 5],'Ytick',1:1:4,'YtickLabel',[],...
'Ygrid','on');
- I want to place the string test in the left lower corner of each rectangle, how can I do it?
- How can I center over the column of rectangles the textboxes containing the date ranges?
Thanks in advance
Respuesta aceptada
Más respuestas (1)
Jan
el 19 de Jul. de 2011
Are the 'test' lables TEXT objects?
Do the rectangles always have the shown position or do you create them dynamically based on some values?
Perhaps this helps already:
TextH(1) = text(0.05, 0.05, 'test', ...
'Units', 'normalized');
TextH(2) = text(0.05 + 1/3, 0.05, 'test', ...
'Units', 'normalized');
TextH(3) = text(0.05 + 2/3, 0.05, 'test', ...
'Units', 'normalized');
TextH(4) = text(1/6, 1.05, 'Header 1', ...
'Units', 'normalized', ...
'HorizontalAlignment', 'center', ...
'VerticalAlignment', 'bottom');
TextH(5) = text(1/3 + 1/6, 1.05, 'Header 2', ...
'Units', 'normalized', ...
'HorizontalAlignment', 'center', ...
'VerticalAlignment', 'bottom');
TextH(6) = text(2/3 + 1/6, 1.05, 'Header 3', ...
'Units', 'normalized', ...
'HorizontalAlignment', 'center', ...
'VerticalAlignment', 'bottom');
6 comentarios
Oleg Komarov
el 20 de Jul. de 2011
Jan
el 20 de Jul. de 2011
@Oleg: Please try what happens with 'character' units, if the figure is resized. E.g. PRINT might perform a silent resize.
Daniel Shub
el 20 de Jul. de 2011
@Jan: Nothing happens since Oleg set the units of the axis to be pixels. If the axis units are normalized, then you are correct, my text moves. You can fix this by setting the units of the text to be "data" or "normalized" after the position is set.
Jan
el 20 de Jul. de 2011
@Daniel: "data" units can fail, if the auto-resizing of the figure changes the axes limits. But "data" units are smart for zooming and panning. However, independent of the applied method to define the locations of text objects, there is always an export method, which distorts the layout :-(
@Oleg: I'm suffering from 1 sec keyboard latency and you pick the _faster_ answer. What a perplexing justice. :-)
@TMW: Please fix this latency stuff soon.
Oleg Komarov
el 20 de Jul. de 2011
Jan
el 20 de Jul. de 2011
@Oleg: export_fig is a good idea!
As you I think that Daniel's answer is useful and usable. And it is worth to keep in mind that there are different methods for setting text locations. I was just kidding about the "justice". Actually my goal is a reduced latency.
Categorías
Más información sobre Graphics Performance en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!