如何消除子图之间的差距 [英] how to remove the gap between subplots and around

查看:93
本文介绍了如何消除子图之间的差距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个图中绘制了两个子图(2x1).我想删除两个子图之间的所有间距,并且也删除顶部子图的xlable和xlabel刻度.另外,我正在尝试删除子图外的所有间距.我尝试

I am plotting two subplots (2x1) in one figure. I would like to remove all the spacing between two subplots and remove the xlable and xlabel ticks for the top subplot too. Also, I am trying to remove all the spacing outside the subplot. I try

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

但是它不起作用.现在,我要手动删除这些边距和标签,我需要处理60个数字,而手动完成所有这些工作非常耗时.还有更好的方法吗?谢谢.

But it doesn't work. Now I am removing those margins and labels manually, I have 60 figures need to be handled and doing all those manually is time consuming. Any better way to do it? Thanks.

我也尝试了subtighttlot,它有助于减少所有边距,但是xlabel和ylabel也被切掉了

I also try the subtightplot, it helps to reduce all the margins but the xlabel and ylabel are also cut

margins=[0 0];
t = 0:0.01:10;
y1 = sin(t);
y2 = cos(t);
h1 = subtightplot(2,1,1, margins);
plot(t, y1);
ystr = {'sin(x)','(dimensionless)'}
hy1 = ylabel(ystr);
set(gca, 'fontsize', 14);
set(hy1, 'fontsize', 14);
set(gca, 'XTickLabel', [],'XTick',[])

h2 = subtightplot(2,1,2,margins);
plot(t, y2, 'r-o');
hx2=xlabel('frequency');
hy2=ylabel('amplitude');
set(gca, 'fontsize', 14);
set(hx2, 'fontsize', 14);
set(hy2, 'fontsize', 14);

我也尝试过subplot_tight,但情况更糟

I also try the subplot_tight but it is even worse

推荐答案

您可以使用 subplot_tight subtighttlot . 删除所有x-tick和标签,请使用:

you can use subplot_tight or subtightplot from the FEX. to remove all x-tick and labels use:

set(gca, 'XTickLabel', [],'XTick',[])

在适当的子图中...

in the appropriate subplot...

由于您确实希望包含标签等,因此可以使用axes中的position手柄进行处理:

Since you do want to include the labels etc, you can so it using the position handle in axes:

t = 0:0.01:10;
y1 = sin(t);
y2 = cos(t);


left= 0.15;
bottom1=0.5;
bottom2=0.05;
width=0.8;
height=0.45; % which is also bottom1-bottom2

axes('Position',[left bottom1 width height]);
plot(t, y1);
ystr = {'sin(x)','(dimensionless)'}
hy1 = ylabel(ystr);
set(gca, 'fontsize', 14);
set(hy1, 'fontsize', 14);
set(gca, 'XTickLabel', [],'XTick',[])


axes('Position',[left bottom2 width height])
plot(t, y2, 'r-o');
hx2=xlabel('frequency');
hy2=ylabel('amplitude');
set(gca, 'fontsize', 14);
set(hx2, 'fontsize', 14);
set(hy2, 'fontsize', 14);

这篇关于如何消除子图之间的差距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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