labels for a graph

1 次查看(过去 30 天)
TJ
TJ 2012-4-25
回答: ag 2024-9-25
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.

回答(1 个)

ag
ag 2024-9-25
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!

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by