Plotted a graph, want to specify label position relative to node

조회 수: 3 (최근 30일)
FM 2021년 6월 7일
댓글: FM 2021년 6월 8일
I plotted a graph, but the node labels sometimes collide:
NodeLabels = arrayfun( @(x)sprintf('x%010u',x) , 1:30 , ...
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
dpb 2021년 6월 8일
You can try varying the 'HorizontalAlignment', 'VerticalAlignment' and perhaps the 'Rotation' properties...
FM 2021년 6월 8일
Hi, does one access those properties? They don't show from issuing "ax". Issuing "ax" at the commad line shows the axis properties and there is an option to "Show all properties", but those properties don't appear in the resulting bigger list.
In the figure itself, I also clicked the button for "Open Property Inspector", but the only labels properties pertain to tick labels. This is also the only context for labels that I can find from an internet search.

댓글을 달려면 로그인하십시오.

채택된 답변

Chunru 2021년 6월 8일
One workaround is to delete the NodeLabel and use text (and then you can control the position):
htext = text(ax.XData, ax.YData, NodeLabels, 'HorizontalAlignment', 'center');
  댓글 수: 1
FM 2021년 6월 8일
Thanks, Chunru. That works perfectly. Each text object in the htext array has it's own set of properties, including 'VerticalAlignment'. I found the following two pages educational:

댓글을 달려면 로그인하십시오.

추가 답변 (0개)


Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by