How to label nodes in a plot?
7 次查看(过去 30 天)
显示 更早的评论
I want to add labels to nodes " D1, D2,....,D23" in my plot and change the color of lines to magenta. Please help.
close all; clear all; clc;
theta=linspace(0,2*pi,24);theta=theta(1:end-1);
[x,y]=pol2cart(theta,1);
links= [-1 -1 0 0 0 0 0 1 0 1 0 0 -1 1 1 -1 1 0 -1 1 -1 1 0;
1 0 0 0 -1 0 0 1 0 1 -1 -1 -1 0 0 -1 -1 -1 0 0 -1 1 0;
1 0 1 0 1 0 0 1 0 0 1 1 -1 1 0 -1 0 0 0 0 -1 -1 0;
1 -1 0 0 -1 0 -1 -1 0 0 -1 1 0 0 0 -1 1 -1 0 -1 -1 0 1;
0 1 -1 0 0 0 -1 1 -1 -1 -1 1 0 0 0 0 -1 0 0 -1 1 0 0;
1 0 0 1 0 0 -1 -1 0 0 0 1 -1 0 0 -1 1 -1 0 -1 -1 1 1;
-1 0 -1 0 1 0 0 1 0 1 0 -1 -1 1 1 0 0 0 0 1 1 0 0;
0 0 -1 0 0 0 1 0 0 1 0 0 1 -1 0 1 0 -1 1 1 -1 1 -1;
0 0 -1 -1 0 0 0 -1 0 -1 0 1 1 0 1 -1 1 -1 -1 -1 -1 0 0;
0 -1 -1 -1 1 0 0 -1 0 0 0 0 1 1 0 -1 1 0 0 -1 -1 0 1;
0 0 1 0 -1 0 -1 0 0 1 -1 -1 0 0 -1 0 -1 0 -1 1 1 1 1;
-1 0 0 1 1 0 -1 -1 0 -1 -1 1 -1 0 -1 0 0 1 0 1 1 0 1;
0 -1 -1 0 1 0 -1 -1 0 -1 0 0 -1 0 0 -1 1 0 0 1 0 0 -1;
0 -1 0 -1 -1 0 0 -1 0 0 0 -1 1 1 0 0 1 0 0 -1 -1 0 0;
-1 0 -1 -1 1 0 0 1 0 1 0 -1 1 1 1 -1 0 0 -1 0 0 -1 -1;
-1 0 0 1 0 -1 -1 -1 0 -1 -1 1 -1 0 0 0 0 0 -1 1 1 1 1;
0 -1 -1 0 1 0 -1 -1 0 -1 0 0 1 0 0 1 0 0 0 1 1 1 -1;
1 1 -1 0 -1 0 -1 1 0 1 -1 -1 -1 0 1 0 -1 -1 0 0 1 0 -1;
0 -1 1 1 0 0 -1 -1 1 1 0 -1 -1 1 0 -1 1 0 -1 0 0 1 0;
0 -1 -1 0 1 0 0 1 0 1 0 0 -1 1 0 1 1 0 -1 0 -1 0 -1;
1 1 -1 1 -1 0 0 0 -1 1 0 0 -1 0 -1 -1 -1 0 1 1 1 1 0];
[ind1,ind2]=ind2sub(size(links),find(links(:)));
h=figure(1);clf(h);
G = plot(x,y,'.k','markersize',20);
hold on
arrayfun(@(p,q)line([x(p),x(q)],[y(p),y(q)]),ind1,ind2);
axis equal off
0 个评论
采纳的回答
Steven Lord
2023-5-26
This matrix looks similar to the one from one of your previous questions. If that's the case, and you plotted the graph object, you could call the labelnode function to label the plot of the graph object and change its properties to change the edge colors or other properties.
g = graph(bucky);
figure
h = plot(g);
nodesToLabel = 3:3:numnodes(g);
labelnode(h, nodesToLabel, "Node " + nodesToLabel)
figure
h = plot(g, 'EdgeColor', 'r');
figure
h = plot(g, 'EdgeColor', 'r');
highlight(h, 5, neighbors(g, 5), 'LineWidth', h.LineWidth*10) % Make edges from 5 ten times thicker
1 个评论
Steven Lord
2023-5-27
The bucky graph was just a simple example. Create your own graph and use the functions I did on that graph.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!