How can I control node label font size of a graph or digraph object?

조회 수: 17 (최근 30일)
Jakob Nikolas
Jakob Nikolas 2016년 2월 8일
답변: Ahmed Khamis 2023년 9월 21일
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
Hang Dong
Hang Dong 2018년 1월 17일
Thank you. This works fine.
Paul Fishback
Paul Fishback 2018년 7월 3일
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)

댓글을 달려면 로그인하십시오.

답변 (4개)

Shruti Sapre
Shruti Sapre 2016년 2월 10일
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
Steven Lord 2019년 10월 22일
You can customize node and edge labels with font properties, including NodeFontSize and EdgeFontSize, as of release R2018b.

Colin Smith
Colin Smith 2017년 8월 23일
any word on this? not only is it crazy that the graph label size can't be changed, but the default size is tiny!

Ahmed Khamis
Ahmed Khamis 2023년 9월 21일
>>
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)
G =
digraph with properties: Edges: [18×1 table] Nodes: [12×0 table]
plot(G,'Layout','force','EdgeColor',"#0072BD",'NodeColor', "#D95319",'NodeFontSize',15,'NodeFontWeight','bold')

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by