Change the alignment and font size of edgelabels
17 ビュー (過去 30 日間)
古いコメントを表示
Hi,
For example, if Ihave the following graph
s = [1 1 1 2 2 3 3 4 4 5 6 7];
t = [2 3 4 5 6 5 7 6 7 8 8 8];
G = digraph(s,t)
eLabels = {'x' 'y' 'z' 'y' 'z' 'x' 'z' 'x' 'y' 'z' 'y' 'x'};
nLabels = {'{0}','{x}','{y}','{z}','{x,y}','{x,z}','{y,z}','{x,y,z}'};
plot(G,'Layout','force','EdgeLabel',eLabels,'NodeLabel',nLabels)
How to change the alignment of the edge labels? Say, from horizontal to vertical and I'd also like to know how to increase the font size of edge labels.
Any suggestions ?
0 件のコメント
採用された回答
Christine Tobler
2020 年 2 月 4 日
The edge labels provided with the plot of a graph can't be modified in terms of their alignment. However, you can add standard text elements, which have more options, in the middle of each edge:
s = [1 1 1 2 2 3 3 4 4 5 6 7];
t = [2 3 4 5 6 5 7 6 7 8 8 8];
G = digraph(s,t);
eLabels = {'textx' 'texty' 'textz' 'texty' 'textz' 'textx' 'textz' 'textx' 'texty' 'textz' 'texty' 'textx'};
nLabels = {'{0}','{x}','{y}','{z}','{x,y}','{x,z}','{y,z}','{x,y,z}'};
h=plot(G,'Layout','force');
[sSorted, tSorted] = findedge(G);
midEdgeX = (h.XData(sSorted) + h.XData(tSorted))/2;
midEdgeY = (h.YData(sSorted) + h.YData(tSorted))/2;
edgelabel = [];
for ii=1:length(eLabels)
[sii, tii] = findedge(G, ii);
edgelabel(ii) = text(midEdgeX(ii), midEdgeY(ii), eLabels(ii), 'HorizontalAlignment', 'right');
end
0 件のコメント
その他の回答 (1 件)
fred ssemwogerere
2020 年 2 月 4 日
編集済み: fred ssemwogerere
2020 年 2 月 4 日
Hello, I think something like this can work nicely:
% Edit the last line of your code to:
h=plot(G,'Layout','force');
h.EdgeLabel=eLabels;
h.NodeLabel=nLabels;
% To change the Edge label font size;
h.EdgeFontSize=12; % '12' is an arbitrary choice here
% To get a list of any other properties of the object you would like to change, just type the name of the object handle, i.e. "h" (my arbitrary variable), in the command prompt.
2 件のコメント
fred ssemwogerere
2020 年 2 月 4 日
Hello, unfortunately, i think there is no option for changing the alignment of labels along the edges of a digraph.
参考
カテゴリ
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!