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!