Rotate and Position Node Labels
조회 수: 13 (최근 30일)
이전 댓글 표시
I am plotting a digraph with node labels. However, the node labels are difficult to see because they are overwritten by the edges. See atatched digraph plot. My questions are the following:
(a) Is it possible to move the node labels so that node labels '066', '065', and '004' are vertical and above their nodes, 'ER' (the node in the middle of the plot) is horizontal and to the right of the node, and the other node labels are vertically below the nodes?
(b) If individal positiioning of the node labels are not possible, can we rotate and move all the node labels by the same amount? Of course, (a) is preferable but I can live with (b) in case (a) is impossible.
Thank you so much.
-- Kamal
댓글 수: 0
채택된 답변
Prahlad Gowtham Katte
2022년 3월 14일
편집: Prahlad Gowtham Katte
2022년 3월 14일
Hello
As per my understanding of your query you wish to customize the position and orientation of the nodes so that they can be seen easily. A possible workaround to achieve the same is by removing the labels and replace them with your own matching text labels. That way you have complete control over the placement of each label. The following code is an example of how you can change the position of a label for a digraph.
G=digraph(s,t,weights,16);
p=plot(G);
p.NodeColor='red';
p.LineWidth=weights;
%Xdata and Ydata are positions of the node starting from 1
p.XData=[10 20 30 40 50 60 70 80 90 100 110 120 60 50 60 70];
p.YData=[30 30 30 30 30 30 30 30 30 30 30 30 60 90 90 90];
%Changing all nodes' labels properties.
text(p.XData-2,p.YData+5,p.NodeLabel, ... %the first 2 arguments provide the position and we can give individual X and Ypositions of each node
'VerticalAlignment','top',...
'HorizontalAlignment', 'left',... % alignment with the node
'FontSize', 9)
%Changing only the first node's label properties
% text([p.XData(1)-2 p.XData(2:end)],[ p.YData(1)+5 p.YData(2:end)] ,p.NodeLabel, ...
% 'VerticalAlignment','top',...
% 'HorizontalAlignment', 'left',... % alignment with the node
% 'FontSize', 9)
%Without this line labels will be duplicated.
p.NodeLabel={};%Changing labels to empty as we have created a text for each label.
For more information on plot properties please refer to the following link.
Hope it helps
추가 답변 (0개)
참고 항목
카테고리
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!