Matlab:重叠的子图标题

时间:2013-05-23 20:18:58

标签: matlab subplot

我正在使用包含三个不同情节的subplot。每个情节都有自己的标签和标题 问题是我保存时必须最大化情节。否则,文本将相互重叠 当我最大化它时,即使我使用ESP格式或任何矢量格式,子图的标签文本在图像中也会显得模糊不清。
我该如何解决这个问题?

4 个答案:

答案 0 :(得分:3)

对于标题重叠问题,您可以使用字符串的单元格数组作为title()的输入参数生成多行标题文本:

title_text = {'first line', 'second line', 'third line'};
title(title_text);

它也适用于标签文本。

答案 1 :(得分:2)

除了Da Kuang的回答,如果您想将标题和标签保持在同一行,您可以更改字体大小

a = axes;
t = title('My Really Long Title');
l = xlabel('My Really Long x label')
set(t, 'FontSize', 8)
set(l, 'FontSize', 8)

答案 2 :(得分:2)

我不确定为什么你的标签模糊,但我可以帮助重叠。

当我想保存图像时(例如纸张),我从不使用subplot。我所做的是分别创建每个轴,这样可以更好地控制每个轴。

下面是一个相当普遍的例子,它说明了如何生成一个任意的网格轴,并且比子图允许的更精细地控制它们的位置。当然,只有3个轴,你真的不需要循环,但我相信你可以根据自己的需要进行调整。

% first create the figure
figPos = [200 200 800 500];
figure('Color', 'w', 'Position', figPos)

% next, determine how much padding you want on each side of the axes, and in
% between axes. I usually play around with these, and the figure size until
% the layout looks correct.

leftPadding = 50/figPos(3); % the space at the left of the figure
rightPadding = 25/figPos(3); % the space at the right of the figure
horizPadding = 80/figPos(3); % the space between axes (horizontally)
topPadding = 30/figPos(4); % the space at the top of the figure
bottomPadding = 50/figPos(4); % the space at the bottom of the figure
vertPadding = 120/figPos(4); % the space between axes (vertically)

% set up the grid size
nHorizAxes = 2;
nVertAxes = 3;

% figure out how big each axes should be
horizPlotSpace = 1-leftPadding-rightPadding-(nHorizAxes-1)*horizPadding;
vertPlotSpace = 1-topPadding-bottomPadding-(nVertAxes-1)*vertPadding;
width = horizPlotSpace/nHorizAxes;
height = vertPlotSpace/nVertAxes;

myAxes = zeros(nVertAxes, nHorizAxes);

% create some sample data to plot for illustrative purposes
x = linspace(0, 2*pi);
y = sin(x);

for iRow = 1:nVertAxes
    for iCol = 1:nHorizAxes
        % calculate the position
        left = leftPadding+(iCol-1)*(width+horizPadding);
        bottom = bottomPadding+(iRow-1)*(height+vertPadding);
        position = [left bottom width height];

        myAxes(iRow, iCol) = axes('Position', position);
        plot(x, y)
        xlabel('Test Label')
        ylabel('Test Label')
        title(sprintf('axes(%d, %d)', iRow, iCol))
    end
end

答案 3 :(得分:0)

这些答案应该有所帮助,但这里有一些其他的尝试,取决于重叠文本的原因:

更改数字的大小,以便有文字空间。例如:

set(gcf, 'PaperSize', [5 7])

更改子图的大小。

s = get(gca, 'Position');
set(gca, 'Position', [s(1), s(2), s(3), s(4) * 0.5])