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!