Draw a line between a point, which has non-normalised coordinates, and a legend, which has a normalised position
24 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sim
el 17 de Ag. de 2024 a las 13:02
Comentada: Star Strider
el 17 de Ag. de 2024 a las 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 comentarios
Respuesta aceptada
Star Strider
el 17 de Ag. de 2024 a las 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Legend en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!