Changing the FontSize of Matlab diagraph plot

조회 수: 15 (최근 30일)
Amir
Amir 2016년 7월 4일
답변: Raimon Fabregat 2017년 5월 18일
Why I can not access any property of FontSize for each nodes in Matlab digraph?
h=figure;
G=digraph(pass_graph);
p=plot(G,'Layout','circle','EdgeLabel',G.Edges.Weight);
p.NodeColor = 'red';
G.Edges.LWidths = 18*G.Edges.Weight/max(G.Edges.Weight);
p.LineWidth = G.Edges.LWidths;
None of the conventional methods I know are working, such as :
fig=gcf;
set(findall(fig,'-property','FontSize'),'FontSize',22)
Or
p=plot(G,'Layout','circle','FontSize',22,'EdgeLabel',G.Edges.Weight);
As a matter of a fact, I don;t see any property for that:
Error using digraph/plot>checkinputnames (line 126)
Expected input number 4 to match one of these strings:
'ArrowSize', 'BusyAction', 'ButtonDownFcn', 'CreateFcn', 'DeleteFcn', 'DisplayName', 'EdgeAlpha', 'EdgeCData',
'EdgeColor', 'EdgeLabel', 'EdgeLabelMode', 'HandleVisibility', 'HitTest', 'Interruptible', 'LineStyle',
'LineWidth', 'Marker', 'MarkerSize', 'NodeCData', 'NodeColor', 'NodeLabel', 'NodeLabelMode', 'Parent',
'PickableParts', 'Selected', 'SelectionHighlight', 'ShowArrows', 'Tag', 'UIContextMenu', 'UserData', 'Visible',
'XData', 'YData', 'Layout', 'Dimension', 'Iterations', 'XStart', 'YStart', 'Direction', 'Sources', 'Sinks',
'AssignLayers'
The input, 'FontSize', did not match any of the valid strings.
Error in digraph/plot (line 80)
args = checkinputnames(args,nameOffset);
  댓글 수: 2
Image Analyst
Image Analyst 2016년 7월 4일
I don't see where you actually tried to access it. Where did you do that? Where did you want the text to be? I know for a fact that title(), xlabel(), ylabel(), and text() all take a 'FontSize' argument, but I don't see you using any of those.
Amir
Amir 2016년 7월 4일
The text I am interested in changing are the Node text of the diagraph, which can't be modified apparently. Even by using matlap graphical figure interface, when I change all fonts, they are the same

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

채택된 답변

Prasad Mendu
Prasad Mendu 2016년 7월 19일
GraphPlot does not support changing the fontsize and fontcolor of the text labels.
As a workaround, if you really need the custom text, grab the XData and YData coordinates from the GraphPlot object, do "hold on", and then superimpose their own custom text labels on the figure by using the TEXT function in MATLAB. Refer to the example below for reference:
% Custom colors from parula colormap and custom sizes between 12 and 20 pts
labelColors = parula(length(names));
labelSizes = randi([12 20], length(names), 1);
p.NodeLabel = {};
% Custom labels
hold on
for i=1:length(names)
text(p.XData(i), p.YData(i), names(i), 'Color', labelColors(i, :), 'FontSize', labelSizes(i));
end
hold off
  댓글 수: 1
Amir
Amir 2016년 7월 19일
편집: Amir 2016년 7월 19일
Nice workaround. that should work i guess.

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

추가 답변 (1개)

Raimon Fabregat
Raimon Fabregat 2017년 5월 18일
What you can do is resize the figure and make it smaller. The font size of the labels will not get rescaled along and they will appear much bigger.

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by