How can I control node label font size of a graph or digraph object?
Mostra commenti meno recenti
I want to plot a graph or digraph (R2015b). Unfortunately, the node labels are barely legible because the font size is too small.
How can I change the font size of the node labels?
My example code is from the Matlab documentation:
s = {'a' 'a' 'a' 'b' 'b' 'c' 'd' 'd' 'd'};
t = {'b' 'c' 'd' 'd' 'a' 'b' 'c' 'a' 'b'};
G = digraph(s,t);
labels = {'a/3' 'a/3' 'a/3' 'b/2' 'b/2' 'c' 'd/3' 'd/3' 'd/3'};
p = plot(G,'Layout','layered','EdgeLabel',labels);
highlight(p,[1 1 1],[2 3 4],'EdgeColor','g')
highlight(p,[2 2],[1 4],'EdgeColor','r')
highlight(p,3,2,'EdgeColor','m')
title('Page Rank Score Transfer Between Nodes')
I would expect p to have a property "NodeLabelFontSize" (or similar), but there is no property to control label appearance.
% get properties of p
get(p)
4 Commenti
Robert
il 8 Giu 2016
Not ideal, but what I ended up doing is removing the node labels and then making my own using text. Something like this:
h = plot(g,'NodeLabel',[])
for i=1:length
text(h.XData(i)+0.1,h.YData(i),num2str(i),'fontsize',16);
end
The placement is fixed to the right of the nodes, but you could do a random offset or try to do something smarter to avoid having the labels overlap edges.
I hope that helps.
khayyam
il 3 Nov 2016
This is an absurd limitation, which is making it very difficult to use the matlab graph functionality for teaching. The node label hack works ok. Edge labels are another problem altogether.
Hang Dong
il 17 Gen 2018
Thank you. This works fine.
Paul Fishback
il 3 Lug 2018
I'm curious to know how this could be modified to change the font size of the edge labels. Using a symmetric matrix A corresponding to a weighted, undirected network, I have
G=graph(A);
plot(G,'EdgeLabel',G.Edges.Weight)
Risposte (4)
Shruti Sapre
il 10 Feb 2016
2 voti
Hi Jakob,
I looked into this and it appears that there currently isn't a way to change the font size of the labels of a graph.
-SHruti
Steven Lord
il 22 Ott 2019
2 voti
You can customize node and edge labels with font properties, including NodeFontSize and EdgeFontSize, as of release R2018b.
Colin Smith
il 23 Ago 2017
0 voti
any word on this? not only is it crazy that the graph label size can't be changed, but the default size is tiny!
>>
s = [1 1 1 2 2 3 3 4 5 5 6 7 7 8 8 9 10 11];
t = [2 3 10 4 12 4 5 6 6 7 9 8 10 9 11 12 11 12];
G = digraph(s,t)
plot(G,'Layout','force','EdgeColor',"#0072BD",'NodeColor', "#D95319",'NodeFontSize',15,'NodeFontWeight','bold')
Categorie
Scopri di più su Graph and Network Algorithms in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
