Best Text/number location on the plot
26 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I want to generate the values of x on each subplot and i was wondering if there is a way to get the text or numbers placed in 'best' location than specifying (x,y) coordinates for the text location.
x(1) on plot 1
x(2) on plot 2 etc inside a forloop
thank you
dan
0 件のコメント
採用された回答
Star Strider
2022 年 7 月 30 日
One approach is to use the legend position after using the 'Location','best' name-value pair, and then interpolating the relative values to the relevant ‘x’ and ‘y’ values (and adding a ‘fudge factor’ if necessary).
x = 1:10;
y = randn(2,size(x,2));
figure
plot(x, y)
Ax = gca;
hl = legend('Location','best');
pos = hl.Position;
txtx = interp1([0 1],xlim,pos(1)*1.1);
txty = interp1([0 1],ylim,pos(2)*1.1);
delete(hl)
text(txtx,txty,'Hi there!')
Experiment to get the desired results.
.
その他の回答 (1 件)
Nikolas
2024 年 6 月 5 日
Another way that may be more intuituve is to find the max of the x any y values and multiply them by a percentage for the location. for example: text(max(xdata)*.10,max(ydata)*0.9,'Heat Exchanger effectiveness'); Which is the equivilant to northwest location
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!