Change label font in Graph plots
Afficher commentaires plus anciens
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?
1 commentaire
Azzi Abdelmalek
le 17 Juil 2016
Post your code
Réponses (1)
Star Strider
le 17 Juil 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:

1 commentaire
Bakht Zaman
le 16 Nov 2016
Thanks alot....
Catégories
En savoir plus sur Annotations dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!