matlab 死区,matlab – 删除死区或增加子图中的图形大小

我回答了这个

at this other topic,并给出了一个

how to improve axes (subplot) space usage here的例子(在函数kmeans_test中搜索子函数setCustomPlotArea).

简短的回答是扩展轴位置占据整个数字如下:

set(gca,'Position',[0 0 1 1]) % Make the axes occupy the whole figure

但是如果你想保留ylabel,xlabel等,你将不得不使用以下方法:

仅删除一个轴的死区

figure

plot([1 3])

title('Cool title')

ylabel('Ylabel yeah')

xlabel('Xlabel nah')

% Approach

tightPos=get(gca,'TightInset')

noDeadSpacePos = [0 0 1 1] + [tightPos(1:2) -(tightPos(1:2) + ...

tightPos(3:4))];

set(gca,'Position',noDeadSpacePos)

这给出了下图:

删除多个轴的死区

我已经调整了setCustomPlotArea,如下所示:

function squeeze_axes(handles)

%

% squeeze_axes(handles) Squeeze axes to remove dead space.

%

% Inputs:

%

% -> handles: the subplot axes handles organized as a grid. I.e.

% handles(1,1) is the axes in the first line and first column, whereas

% handles(4,4) is the axes in the forth line and forth column.

%

% - Creation Date: Mon, 16 Sep 2013

% - Last Modified: Tue, 17 Sep 2013

% - Author(s):

% - W.S.Freund

% TODO: Make squeeze axes compatible with axes that occupy multiple

% subplot places.

nHorSubPlot = size(handles,2);

nVertSubPlot = size(handles,1);

subplotWidth = 1/nHorSubPlot;

subplotHeight = 1/nVertSubPlot;

botPos = linspace(1-subplotHeight,0,nVertSubPlot);

leftPos = linspace(0,1-subplotWidth,nHorSubPlot);

for curLine=1:nVertSubPlot

for curColumn=1:nHorSubPlot

curAxes = handles(curLine,curColumn);

if curAxes

% Set OuterPosition to occupy as most space as possible

curAxesOuterPos = [leftPos(curColumn) botPos(curLine) subplotWidth ...

subplotHeight];

set(curAxes,'OuterPosition',curAxesOuterPos);

% Remove dead space inside subplot border:

curAxesTightPos=get(curAxes,'TightInset');

noDeadSpacePos = curAxesOuterPos + [curAxesTightPos(1:2) ...

-(curAxesTightPos(1:2) + curAxesTightPos(3:4))];

set(curAxes,'Position',noDeadSpacePos)

end

end

end

end

绘制常见的matlab子图函数如下:

figure

nLines = 2;

nColumns = 3;

handles = zeros(nLines,nColumns)

for line = 1:nLines

for column = 1:nColumns

handles(line,column)=subplot(nLines,nColumns,column+(line-1)*nColumns);

plot([line column]);

title(sprintf('Cool title (%d,%d)',line,column))

ylabel(sprintf('Ylabel yeah (%d,%d)',line,column))

xlabel(sprintf('Xlabel nah (%d,%d)',line,column))

end

end

给你:

删除其死空间:

squeeze_axes(handles)

作为练习,我让你有一个轴占据网格中多个空间的情况.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值