sta*_*tor 7 matlab plot label figure
我有以下脚本最终绘制一个4乘2的子图:
files = getAllFiles('preliminaries');
n = size(files);
cases = cell(1, n);
m = cell(1, n);
for i = 1:1:n
S = load(files{i});
cases{i} = retransmission_distribution(S);
c = size(cases{i});
m{1,i} = cell(1, c(2));
%figure(i);
str_size = size(files{i});
title_str = files{i}(5:str_size(2) - 4);
title_str = strrep(title_str, '_', ' ');
%title(title_str);
for j = 1:1:c(2)
[x, y] = hist(cases{i}{1,j});
m{1,i}{1,j} = [x; int32(y)];
% subplot(4, 2, j);
% xlabel('Number of Retransmissions');
% ylabel('Number of Occurrences');
% bar(y, x, 'histc');
end
end
Run Code Online (Sandbox Code Playgroud)
但是,根据我的命令序列的当前顺序,即使它们未被注释,标题和轴标签在被擦除之前也存在一段时间.我希望图中有自己的标题,每个子图都有自己的轴标签.修复它的最简单方法是什么?
对于轴标签,Matt在调用BAR 之后必须放置它们是正确的.这将解决一个轴标签问题.但是,您可能会注意到,如果y轴标签太长,您的y轴标签可能最终会被写入.你有几个选择来解决这个问题.首先,您可以在调用YLABEL时调整字体大小:
ylabel('Number of Occurrences','FontSize',7);
Run Code Online (Sandbox Code Playgroud)
其次,您可以使用字符串的单元格数组而不是单个字符串将一个长标签转换为多行标签:
ylabel({'Number of' 'Occurrences'});
Run Code Online (Sandbox Code Playgroud)
要为整个图形添加标题,最好的选择可能是制作一个UICONTROL静态文本对象并调整其位置,使其位于图的顶部附近.您可以先获取图形的大小和位置,以帮助您将文本框放在顶部和中心附近:
figureSize = get(gcf,'Position');
uicontrol('Style','text',...
'String','My title',...
'Position',[(figureSize(3)-100)/2 figureSize(4)-25 100 25],...
'BackgroundColor',get(gcf,'Color'));
Run Code Online (Sandbox Code Playgroud)
这将创建一个宽度为100像素,高度为25像素的静态文本框,位于图形顶部的中心,背景颜色与图形相同.
suptitle是您要查找的内容。
它将标题置于所有图上方的中心。
SUPTITLE Puts a title above all subplots.
SUPTITLE('text') adds text to the top of the figure
above all subplots (a "super title"). Use this function
after all subplot commands.
Run Code Online (Sandbox Code Playgroud)