How to index/address the chart width and height using Position option in Text command?
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi all,
I have this line of code. Suppose I want to use text using half of width and height of my figure. How shouldI index/address that in Text command?
Geo = figure()
Geo.Position;
Geo.Position(1:4) = [ 100 100 560 420]; % buttom left > Width Height <
a = Width./2 %this is where my problem is. how to get that width pixel out of the line above and use it as a position in chart
b = Height./2
text(a,b,(['mean = ']));
xlim([1 5]) %I odn't want to use xlim because everychart of mine will be different.
댓글 수: 0
채택된 답변
dpb
2021년 6월 6일
편집: dpb
2021년 6월 6일
pos=Geo.Position; % save as array
x=pos(1)+pos(3)/2; % midpoint position horizontal
y=pos(2)+pos(4)/2; % midpoint position vertical
text(x,y,(['mean = ']));
NB: however, that text() uses the axes positions, not the figure position coordinates that are retuned by the 'Position' property and that are relative to the actual monitor/display, NOT the axes/figure itself. Those two coordinate positions don't relate to each other.
If the idea is to put the text at the middle of the x- and y- current axes, then using
hTxt=text(0.5,0.5,'Mid-Axes Text','units','normalized','horizontalalign','center');
will put the text at the middle axes range irrespective of x-, y- data limits without trying to compute pixel locations.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!