MATLAB Answers

How to index/address the chart width and height using Position option in Text command?

조회 수: 1(최근 30일)
Wolfgang McCormack
Wolfgang McCormack 2021년 6월 6일
댓글: Wolfgang McCormack 2021년 6월 6일
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(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.

채택된 답변

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.
  댓글 수: 1
Wolfgang McCormack
Wolfgang McCormack 2021년 6월 6일
@dpb thanks yes i want to put it at the top of y axis but in middle of x. Thank you again

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by