Xlabel coordinates for text command?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Djordje Damnjanovic
el 13 de Dic. de 2020
Respondida: Djordje Damnjanovic
el 14 de Dic. de 2020
Hello everybody!
I have question. I'm using matlab 2014b and I need to find coordinates of xlabel text on the figure. That coordinates I will use later in the text() command for something else. So it is like this:
- I have this part in Figure:
xlabel('{\it t} [s]','FontName','times','FontSize',8)
And then I do this:
x1=get(get(gca,'XLabel'),'Position');
x1 returns as a vector with 4 coordinates x1[a b c d] where a is x-coordinate, b is y-coordinate, c is weight and d is height if I'm right.
Now if I use a and b values from x1 vector for text() command:
text(a , b, '(a)', 'HorizontalAlignment','right', 'VerticalAlignment','middle','FontName','times','FontSize',8);
(a) is not in the same spot as xlabel was.
So my question is where do I make mistake? is the units different in x1 and text?
Basicly I need do obtain exact same coordinates for xlabel, put it in text command for some other text in figure.
0 comentarios
Respuestas (3)
Mario Malic
el 13 de Dic. de 2020
Editada: Mario Malic
el 13 de Dic. de 2020
Hi,
XLabel and Text are of the same type, so they have same properties. Default settings for text are center and middle alignments, but you align your text on the right side which probably is the issue.
xLabel = get(gca,'XLabel');
labelText= text(a , b, '(a)', 'HorizontalAlignment','right', 'VerticalAlignment','middle','FontName','times','FontSize',8);
The bottom command saves the handle to the text label, you can open it in property browser and inspect if there are some unusual differences between label and text.
Note: You have version 2014 and nowadays it's different, there are only 3 coordinates that define Position property of text. Consult with documentation and check what exactly these are, if you have 4 coordinates.
Matt Gaidica
el 13 de Dic. de 2020
h = figure('position',[0 0 600 800]);
x = xlabel('{\it t} [s]','FontName','times','FontSize',12);
text(x.Position(1) , x.Position(2), '{\it t} [s]', 'FontName','times','FontSize',12,...
'HorizontalAlignment',x.HorizontalAlignment, 'VerticalAlignment',x.VerticalAlignment);
It will become unaligned if you manually resize vertically. If this doesn't work, maybe explain your application a little more? It seems like a hack.
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!