Xlabel coordinates for text command?
조회 수: 4 (최근 30일)
이전 댓글 표시
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
답변 (3개)
Mario Malic
2020년 12월 13일
편집: Mario Malic
2020년 12월 13일
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
2020년 12월 13일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!