MATLAB子图标题和轴标签 [英] MATLAB subplot title and axes labels

查看:1062
本文介绍了MATLAB子图标题和轴标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下脚本来最终绘制4 x 2子图:

I have the following script to ultimately plot a 4 by 2 subplot:

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

但是,按照我当前的命令顺序顺序,即使不加注释,标题和轴标签也会存在一段时间,然后才被删除.我希望该图具有其自己的标题,每个子图都有其自己的轴标签.最简单的解决方法是什么?

However, with the current order of command sequence I have, even with them uncommented, the title and axis labels were present for a time before being erased. I want the figure to have its own title, with each subplot having its own axis labels. What's the easiest way to fix it?

推荐答案

对于轴标签, YLABEL :

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:

ylabel('Number of Occurrences','FontSize',7);

第二,您可以使用

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:

ylabel({'Number of' 'Occurrences'});

要在整个图形中添加标题,最好的选择可能是使 UICONTROL 静态文本对象,并调整其位置,使其放置在图的顶部附近.您可以先获取图形的大小和位置,以帮助您将文本框放在顶部和中央附近:

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:

figureSize = get(gcf,'Position');
uicontrol('Style','text',...
          'String','My title',...
          'Position',[(figureSize(3)-100)/2 figureSize(4)-25 100 25],...
          'BackgroundColor',get(gcf,'Color'));

这将创建一个静态文本框,该文本框的宽度为100像素,高度为25像素,位于图的顶部中心,并且背景颜色与图相同.

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.

这篇关于MATLAB子图标题和轴标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆