labels for a graph

8 ビュー (過去 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 Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by