Draw a line between a point, which has non-normalised coordinates, and a legend, which has a normalised position
24 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Sim
il 17 Ago 2024 alle 13:02
Commentato: Star Strider
il 17 Ago 2024 alle 16:03
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 Commenti
Risposta accettata
Star Strider
il 17 Ago 2024 alle 13:37
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.
.
2 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Legend in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!