フィルターのクリア

Draw a line between a point, which has non-normalised coordinates, and a legend, which has a normalised position

2 ビュー (過去 30 日間)
I want to draw a line between a point (which has non-normalised coordinates) and a legend (which has a normalised position).
xp = 34573;
yp = 89832;
p = plot(xp,yp,'o','MarkerFaceColor','b');
lgd = legend(p);
It would be easy if both the point coordinates and the legend position were either both normalised or both non-normalised. Indeed, I would like to use something similar to this:
plot([xp lgd.Position(1)],[yp lgd.Position(2)])
but it does not work, since they have a different normalization.
Therefore, is there a way to transform either the non-normalised coordinates into normalised coordinates, or viceversa?

採用された回答

Star Strider
Star Strider 2024 年 8 月 17 日
I wrote my osn set of utility functions for my own use for these sorts of problems. The approach I use here is to find the normalised coordinates of the point, and use the ‘left’ and ‘lower’ legend position values to draw the annotation arrow.
Try this —
xp = 34573;
yp = 89832;
p = plot(xp,yp,'o','MarkerFaceColor','b');
lgd = legend(p);
lgdpos = lgd.Position;
xapf = @(x,pos,xl) pos(3)*(x-min(xl))/diff(xl)+pos(1); % 'x' Annotation Position Function
yapf = @(y,pos,yl) pos(4)*(y-min(yl))/diff(yl)+pos(2); % 'y' Annotation Position Function
xl = xlim;
yl = ylim;
pos = gca().Position;
pointpos = [xapf(xp,pos,xlim), yapf(yp,pos,ylim)];
annotation('arrow', [pointpos(1) lgdpos(1)], [pointpos(2) lgdpos(2)])
Make appropriate changes to get the result you want.
.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by