Draw a line between a point, which has non-normalised coordinates, and a legend, which has a normalised position
조회 수: 3 (최근 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?
댓글 수: 0
채택된 답변
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 Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!