MATLAB 子图标题和轴标签
我有以下脚本来最终绘制 4 x 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
但是,按照我当前的命令序列顺序,即使未注释它们,标题和轴标签也会在被删除之前存在一段时间。我希望该图有自己的标题,每个子图都有自己的轴标签。修复它最简单的方法是什么?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
对于轴标签,Matt 关于它们必须放置在调用 BAR 之后 。这将解决一个轴标签问题。但是,您可能会注意到,如果 y 轴标签太长,它们最终可能会被相互覆盖。您有几个选项可以解决此问题。首先,您可以将调用中的字体大小调整为 YLABEL< /a>:
其次,您可以使用 字符串单元格数组 而不是单个字符串:
要向整个图形添加标题,最好的选择可能是制作 UICONTROL 静态文本对象并调整其位置,使其放置在顶部附近该图的。您可以先获取图形的大小和位置,以帮助您将文本框放置在顶部和中心附近:
这将创建一个宽度为 100 像素、高度为 25 像素的静态文本框,放置在图形顶部的中心并具有与图相同的背景颜色。
For the axis labels, Matt is correct about them having to be placed after the call to BAR. That will take care of one axis label problem. However, you'll likely notice that your y-axis labels in particular may end up being written over one another if they are too long. You have a couple of options to fix this. First, you can adjust the font size in your call to YLABEL:
Second, you can convert one long label into a multi-line label by using a cell array of strings instead of just a single string:
To add a title to the entire figure, the best option is probably to make a UICONTROL static text object and adjust its position so it is placed near the top of the figure. You can get the size and the position of the figure first to help you place the text box near the top and center:
This will create a static text box of width 100 pixels and height 25 pixels placed at the center of the top of the figure and with the same background color as the figure.
suptitle 就是您要找的内容。
它将标题置于所有图上方的中心。
suptitle is what you are looking for.
It places the title centered above all plots.
这是我不久前在 MATLAB 交流论坛上看到的一个解决方案,它对我来说非常有效。创建图形后,执行以下命令序列:
Here's a solution I saw on a MATLAB exchange forum a while back and that worked for me pretty well. After creating the figure, execute the following sequence of commands:
据我所知,标题函数将文本相对于一组轴放置,因此不存在图形标题之类的东西。可能的解决方法包括仅对放置良好的子图使用标题(例如第一个子图或顶行的中间子图),或者在您想要标题的位置手动创建一组轴。
至于轴标签,请尝试将标签命令放在条形命令之后。
As far as I know the title function places text relative to a set of axes, so there is no such thing as a figure title. Possible workarounds include using title for a well placed subplot only (such as the first one, or the middle one of the top row), or manually creating a set of axes in the location where you want your title.
As for the axis labels, try putting the label commands after the bar command.