Borrar filtros
Borrar filtros

Change the alignment and font size of edgelabels

11 visualizaciones (últimos 30 días)
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 ?

Respuesta aceptada

Christine Tobler
Christine Tobler el 4 de Feb. de 2020
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
See the doc page of text for more options.

Más respuestas (1)

fred  ssemwogerere
fred ssemwogerere el 4 de Feb. de 2020
Editada: fred ssemwogerere el 4 de Feb. de 2020
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 comentarios
Deepa Maheshvare
Deepa Maheshvare el 4 de Feb. de 2020
Hi, Thank you. I tried your suggestion
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');
h.EdgeLabel=eLabels;
h.NodeLabel=nLabels;
h.EdgeFontSize=12; % '12' is an a
Unfortunately, the alignment of text of edgelabels doesn't change. I want the edge labels to be oriented perpendicular to the edge i.e vertical .
Any suggestions?
fred  ssemwogerere
fred ssemwogerere el 4 de Feb. de 2020
Hello, unfortunately, i think there is no option for changing the alignment of labels along the edges of a digraph.

Iniciar sesión para comentar.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by