labels for a graph
Mostrar comentarios más antiguos
I am plotting a graph using
gplot(G.adjM,G.Vxy,'o:')
How would I "label" the vertices with the respective indices?
I prefer the labels to appear only when I select a vertex instead of text on the graph since the graph could get very messy. Currently this will give me the (X,Y) coordinates of the point.
Respuestas (1)
ag
el 25 de Sept. de 2024
Hello TJ,
To display the labels upon selecting a vertex, you can utilise the "datacursormode". You can use data cursor mode to explore data by interactively creating and editing data tips.
The below code snippet demonstrates how to display the coordinates of a data point, upon selection:
x = 1:10;
y = x.^2;
scatter(x,y)
dcm = datacursormode;
dcm.Enable = 'on';
dcm.UpdateFcn = @displayFunc;
function txt = displayFunc(~,info)
x = info.Position(1);
y = info.Position(2);
myDatatipText = "(%s, %s)";
txt = sprintf(myDatatipText, num2str(x), num2str(y));
end
The above code can be modified as per your use case, to display the labels instead of the coordinates of the point.
For more details, please refer to the following MathWorks documentation: datacursormode - https://www.mathworks.com/help/matlab/ref/matlab.graphics.shape.internal.datacursormanager.html
Hope this helps!
Categorías
Más información sobre Annotations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!