Change label font in Graph plots
18 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am plotting a Graph object (created using the graph function). I figured out how to label nodes and edges in my graph, but I do not know how to change the font size and weight for the label text. How can it be done?
Respuestas (1)
Star Strider
el 17 de Jul. de 2016
You can change the node labels (that I assume you are referring to) by using a text object.
This code is from the documentation for graph, with my tweaks to change the node label font size:
s = [1 1 1 2 2 3 3 4 5 5 6 7];
t = [2 4 8 3 7 4 6 5 6 8 7 8];
weights = [10 10 1 10 1 10 1 1 12 12 12 12];
names = {'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H'};
G = graph(s,t,weights,names);
figure(1)
h = plot(G,'EdgeLabel',G.Edges.Weight);
nl = h.NodeLabel;
h.NodeLabel = '';
xd = get(h, 'XData');
yd = get(h, 'YData');
text(xd, yd, nl, 'FontSize',20, 'FontWeight','bold', 'HorizontalAlignment','left', 'VerticalAlignment','middle')
The plot:

Ver también
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!