Coordinates of nodes in plot graph

7 vues (au cours des 30 derniers jours)
Maximilian Krahn
Maximilian Krahn le 1 Fév 2021
Hi,
after displaying a graph with the "Force Directed" algorithm by calling
plot(graph(G), 'force')
I would like to get the coordinates of the nodes of the displayed graph. Is there a way to extract them or to only call the "Force Directed" algorithm to get those?
Best Regards

Réponse acceptée

Steven Lord
Steven Lord le 1 Fév 2021
Copying my answer from this Answers post:
B = graph(bucky);
h = plot(B);
X = h.XData;
Y = h.YData;
fprintf("Node 1 is located at (%f, %f)\n", X(1), Y(1))
Node 1 is located at (0.103347, -1.803899)
% Turn on the axes ticks so you can check the coordinates
ax = ancestor(h, 'axes');
ax.XTickMode = 'auto';
ax.YTickMode = 'auto';
xticks(-5:5)
% Draw lines -- X marks the spot
xline(X(1), 'r')
yline(Y(1), 'r')

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by