Node lablel overlaping Edge lable
1 view (last 30 days)
Show older comments
Node lablels are overlaping Edge lables , as per the attached photo , what can i do to avoide that situation , also i wanna change the Node lable to be on the center of the Node not on the right of it
4 Comments
Answers (1)
Kausthub
on 14 Sep 2023
Hi Mohamed,
I understand that while plotting the graph, the edge labels are overlapping, and you would like to align the node labels to the centre instead of right alignment.
The overlapping error occurs due to the “Adjusting Xdata and YData to show Feeders separately” step where you assign the same Xdata to multiple nodes.
h.XData(:,id)= startxdata;
Instead, you could add a small random number to Xdata to make all the edges visible and remove the overlapping.
h.XData(:,id)= startxdata + 100*rand(1);
In case of aligning the nodes to the centre, there is a no documented property of ‘GraphPlot’ (https://www.mathworks.com/support/search.html/answers/477770-is-it-possible-to-change-the-position-of-graph-plot-node-labels.html) that allows you to change the placement of the labels relative to the nodes. However, you could remove the labels and replace them with your own matching text labels. That way you have complete control over the placement of each label. The bellow mentioned snippet does this for you:
text(h.XData, h.YData, h.NodeLabel,...
'HorizontalAlignment', 'center', 'FontSize', 8);
h.NodeLabel={};
Here is a MATLAB Answer which addresses the issue of positioning the node labels: https://www.mathworks.com/support/search.html/answers/477770-is-it-possible-to-change-the-position-of-graph-plot-node-labels.html
I am also attaching the updated code for better understanding.
Hope this helps and clarifies your issue regarding overlapping node labels and aligning them to the centre!
0 Comments
See Also
Categories
Find more on Graph and Network Algorithms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!