Plotted a graph, want to specify label position relative to node
1 view (last 30 days)
Show older comments
I plotted a graph, but the node labels sometimes collide:
A=ceil(10*rand(30));
A=triu(A,1)+triu(A,1)';
NodeLabels = arrayfun( @(x)sprintf('x%010u',x) , 1:30 , ...
'Uniform',false);
GportDist = graph( A , NodeLabels );
ax=plot( GportDist, 'Layout','force' , ...
'WeightEffect','direct' , 'Interpreter','none');
I haven't found a way to specify the label position relative to the node, e.g., North, NorthEast, South, etc.
Is there a way to specify label positions relative to nodes?
I am using Matlab 2019a.
2 Comments
dpb
on 8 Jun 2021
You can try varying the 'HorizontalAlignment', 'VerticalAlignment' and perhaps the 'Rotation' properties...
Accepted Answer
Chunru
on 8 Jun 2021
One workaround is to delete the NodeLabel and use text (and then you can control the position):
ax.NodeLabel={};
htext = text(ax.XData, ax.YData, NodeLabels, 'HorizontalAlignment', 'center');
More Answers (0)
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!