labels for a graph

조회 수: 12 (최근 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에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by