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

4 ビュー (過去 30 日間)
FM
FM 2021 年 6 月 7 日
コメント済み: FM 2021 年 6 月 8 日
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 件のコメント
dpb
dpb 2021 年 6 月 8 日
You can try varying the 'HorizontalAlignment', 'VerticalAlignment' and perhaps the 'Rotation' properties...
FM
FM 2021 年 6 月 8 日
Hi, dpb....how 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
Chunru 2021 年 6 月 8 日
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');
  1 件のコメント
FM
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:
  1. https://www.mathworks.com/help/matlab/ref/text.html
  2. https://www.mathworks.com/help/matlab/ref/matlab.graphics.primitive.text-properties.html

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by