您的位置:首页 > 编程语言 > MATLAB

matlab画图,如何消除图形中多余的空白区域

2014-06-17 10:46 369 查看
matlab图形的gca中,主要由position、outerPostion、以及tightInset来决定坐标轴,图形,标注等的位置。举例如下:

N = 100;

x = 1:N;

y = rand(1,N);

set(gcf, 'PaperSize', [5 3], 'PaperPosition', [0 0 5 3]);

delete(gca); clf; % Clean up the figure

plot(x, y);

h=zeros(1,3);

h(1) = annotation('rectangle', get(gca, 'Position'), 'Color', 'Magenta');

h(2) = annotation('rectangle', get(gca, 'OuterPosition'), 'Color', 'Yellow');

h(3) = annotation('rectangle', get(gca, 'Position') + ...

get(gca, 'TightInset') * [-1 0 1 0; 0 -1 0 1; 0 0 1 0; 0 0 0 1], ...

'Color', 'Red');

set(h,'LineWidth', 3);



可以看到很大部分的空白,如何方便快速的消除这些空白呢?两种方法:

1、输入:

set(gca, 'Position', get(gca, 'OuterPosition') - ...

get(gca, 'TightInset') * [-1 0 1 0; 0 -1 0 1; 0 0 1 0; 0 0 0 1]);

效果如下:

delete(gca); clf;

plot(x, y);

set(gca, 'Position', get(gca, 'OuterPosition') - ...

get(gca, 'TightInset') * [-1 0 1 0; 0 -1 0 1; 0 0 1 0; 0 0 0 1]);

h = zeros(1,2);

h(1) = annotation('rectangle', get(gca, 'Position'), 'Color', 'Magenta');

%annotation('rectangle', get(gca, 'OuterPosition'), 'Color', 'Yellow');

h(2) = annotation('rectangle', get(gca, 'Position') + ...

get(gca, 'TightInset') * [-1 0 1 0; 0 -1 0 1; 0 0 1 0; 0 0 0 1], ...

'Color', 'Red');

set(h,'LineWidth', 3);



2.、输入matlab一个未公布的命令:

set(gca,'LooseInset',get(gca,'TightInset'))

也可以达到同样的效果。

另外,有谁能告诉bode(tf(1,[1 1]))之后,再把图片缩小后,下面的x轴标准会被挡住,该如何解决?



我试了很多方法,,貌似都不行。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: