Adding multiple labels to a graph
26 次查看(过去 30 天)
显示 更早的评论
I have the following graph:
s = [1 2 3 4 6 7 8 10];
t = [3 3 4 5 7 5 9 11];
G = digraph(s,t);
h = plot(G);
and want to add the following labels to the nodes
schedule = [0 0 1 2 3 1 2 2 3 2 3];
I am struggling to manage this with my basic Matlab knowledge. I want to display the node numbers (here: [1:1:11]) and the corresponding values from the schedule array.
0 个评论
采纳的回答
Voss
2022-12-6
s = [1 2 3 4 6 7 8 10];
t = [3 3 4 5 7 5 9 11];
G = digraph(s,t);
h = plot(G);
% schedule = [0 0 1 2 3 1 2 2 3 2 3];
yd = get(h,'YData');
schedule = max(yd)-min(yd)-yd+1
text(get(h,'XData')-0.1,yd,string(schedule), ...
'HorizontalAlignment','right', ...
'EdgeColor','k', ...
'FontSize',8)
更多回答(1 个)
Maik
2022-12-6
% You can use nodenames propertiest of digraph. However the names must be unique
s = [1 2 3 4 6 7 8 10];
t = [3 3 4 5 7 5 9 11];
weights = ones(1,8);
names = {'A' 'B' 'C' 'D' 'E' 'F' 'G 4' 'H 5' '1' '2' '3'};
G = digraph(s,t,weights,names)
h = plot(G)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graph and Network Algorithms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!